-1

I am trying to access a managed function from native code. I created a c++/cli dll in visual studio 2010 with CLR option. This is my c# code:

namespace ManagedNamespace { public class Managed { public void CSharpFunc() { . . . } } } 

This is my c++\CLI code (the project refer to the c# project - and I compile this code to Wrapper.dll):

#ifdef __cplusplus extern "C" { #endif __declspec(dllexport) void CLIFunc(const std::string& a, const std::string& b, std::string& c) { System::String^ new_a = gcnew System::String(a.c_str()); //OK System::String^ new_b = gcnew System::String(b.c_str()); //OK Text::StringBuilder^ new_c = gcnew Text::StringBuilder(""); //OK ManagedNamespace::Managed^ m = gcnew ManagedNamespace::Managed(); //this line is the problematic line m->CSharpFunc(); } 

I call this function from another dll and get EXCEPTION_EXECUTE_HANDLER when I create ManagedNamespace::Managed object. This is the code:

typedef void (WINAPI *CLIFuncPtr)(const std::string& a, const std::string& b, std::string& c); . . . HMODULE mod = LoadLibraryA("c:\\mydir\\Wrapper.dll"); if (mod!= NULL) { CLIFuncPtr FuncPtr = (CLIFuncPtr)GetProcAddress(mod, "CLIFunc"); if (FuncPtr != NULL) { FuncPtr (aa, bb, cc); } } 

Appreciate any help, Thanks

4
  • What is the exact error message? Commented Jul 17, 2013 at 8:50
  • Is this relevant? stackoverflow.com/questions/6628412/… Can you make the debugger break on all exceptions and see what's gone wrong? Commented Jul 17, 2013 at 8:52
  • exception: EEFileLoadException * _ptr64 at memory location 0x.... Commented Jul 17, 2013 at 10:27
  • The CLR has no hope of finding your C# assembly if you don't copy it in the same directory as the EXE. The backup plan is to register it in the GAC so it can always be found. Commented Jul 17, 2013 at 14:38

1 Answer 1

0

I think that LoadLibrary works only with unmanaged code

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.