creating C .dll and using it in C# -


as c# developper i'm trying learn c now. seemed me fun create c dll , use functions created in c# project, familiar language.

for developping c dll use dev-c++ , c# visual studio.

this i've come far:

c

#include <windows.h> #include <stdio.h> #include <stdlib.h>  #define nag_call __stdcall  #define nag_dll_expimp  __declspec(dllexport)  nag_dll_expimp void nag_call scalars(double, double*); nag_dll_expimp void nag_call scalars(double in, double *out) {   *out = in; } 

and in c#

using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices;  namespace testmyowncdll {     public static class mycdllwrapper     {         [dllimport("testdll1.dll")]         private static extern void scalars(double invar, ref double outvar);          public static double callscalars(double invar)         {             double outvar = (double)0.0;             scalars(invar, ref outvar);             return outvar;         }      } } 

i've added tastdll1.dll assembly , marked 'always copy'. however, when calling function badimageformatexception. means dll found can't execute dll reason.

any ideas? i've used examples from: http://www.drdobbs.com/cpp/calling-c-library-dlls-from-c/184406285

kind regards.

solved error: devc++ compiler compiles in x64 while target platform c# application set x86. changing target platform x64 solves error.

now, there possibility compile anycpu c dll's?


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -