c# 4.0 - LoadLibrary not working while loading DLL built using Eclipse Neon 3 -
i have dlls core c++ projects, created using eclipse editor c/c++ developers. version neon.3 release (4.6.3). have used cygwin 64-bit compiler build c++ project.
here sample code core c++ project, created , built in eclipse:
__declspec(dllexport) int addition(int a,int b) { return (a+b); }
now, want call functionalities these dlls in managed c++ project. that, loadlibrary method used full path specified dll loaded. furthermore, have windows forms application ui enter input , display results. application created using c#, in vs2010. results received calling managed c++ project method, internally calls core c++ project method.
this expected work. facing problem when try debug. loadlibrary call ends debugging session, without raising exception. have wrapped call in try-catch exception isn't caught.
but when run c# exe out folder, surprisingly working , giving expected results.
here managed c++ code snippet loading dll built in eclipse:
namespace addfromeclipse { #define add (int a,int b) typedef int (* engadd) add; typedef int (*f_funci)(int a,int b); a::a(){} int a::call() { int a; cout<<"inside c++"<<endl; hinstance hgetprociddll; try{ hgetprociddll = loadlibrary(l"d:\\eclipse\\out\\myadd.dll"); //hgetprociddll = loadlibrary(l"myadd.dll"); }catch(...) { cout<<"unable load function"<<endl; } if(hgetprociddll != null) { f_funci funci = (f_funci)getprocaddress(hgetprociddll, "addition"); if(funci != null) { = funci(10,20); cout<<"addition :"<<a<<endl; } else { cout<<"unable load function"<<endl; } } else { unsigned long lerr = getlasterror(); cout<<"unable load dll"<<endl; } return 0; } };
following c# code calling managed c++ method simple addition:
using system; using addfromeclipse; namespace execute { class program { static void main(string[] args) { try { console.writeline("inside me c#"); obj = new a(); obj.call(); console.writeline("back c#"); console.readkey(); } catch (exception exception) { system.windows.forms.messagebox.show(exception.message); } } } }
does know how work out?
any appreciable.
thank you.
Comments
Post a Comment