c++ - How export old C dll for use in C# Class Library -


there 2 old c files tow related headers.
use them in visual studio 2013 created visual c++ win32 console application , disabled precompiled headers properties of project.
deleted stdafx.h & targetver.h & dllmain.cpp && project_name.cpp(created vs).
in header files area added 2 files , in source files area added tow files.
project :

[my project]

here entire project's link

consider on .c file extensions(no .cpp).
in header files there no class usage , see many structs in there because of old c language.
want export project's dll use in simple console application c# project.
how can that?
put peace of code in upper of both header files :

__declspec(dllexport) int main(); 

int main() function inside wmm_file.c file , main function uses many functions in c file (geomagnetismlibrary.c).
want use functions of c++ project in c# code.
here c# codes (prpogram.cs) :

using system; using system.collections.generic; using system.linq; using system.runtime.interopservices; using system.text; using system.threading.tasks;  namespace consoleapplication1 {     class magnetic_model_csharp          [dllimport(@"y:\magnetic_model_c_dll_2.dll", callingconvention = callingconvention.cdecl)]         public static extern int main();          static void main(string[] args)         {             main();         }     } } 

and here error after run :

an unhandled exception of type 'system.accessviolationexception' occurred in magnetic_model_csharp.exe

how can fix error , make c(c++) project exportable?

edit :
friends said shouldn't use main keyword renamed it.
test created simple
declaration :

int add(int a, int b); /* put on geomagnetismheader.h file*/ 

definition :

int add(int a, int b) /* put on wmm_file.c file > renamed main() main_____() in file*/ {     printf("hello joy!\r\n");     return + b; } 

and renamed both

__declspec(dllexport) int main();  

to

__declspec(dllexport)   

in both header files.
problem position of declaration of int add(int a, int b); function in geomagnetismheader.h file.
when put before typedef struct { works.
when put after typedef struct { not work , of declarations after typedef struct {.
idea?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -