Calling a function inside another .dll

Hello,

I am a .NET developer and am trying to call a function inside a .dll that was written in C++. With the limited experience I have with C++ and the research I've done, I don't believe I can call the function I want because it was not created with the "extern" flag. With that said, I have written a wrapper .dll that I *can* call from .NET, however the problem now is that my wrapper .dll is not properly calling the function it's supposed to be wrapped around. Namely, my .dll is defined as follows:


#include "SysInfo.h"
#include <string>
using namespace std;

BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) {
return TRUE;
}

extern "C" __declspec(dllexport) int __stdcall ChkSecurity() {

HINSTANCE hGetProcIDDLL = LoadLibrary("D:\\Bigy\\apps\\Turnkey\\Programs\\BigYSymbol.dll");

FARPROC ProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "ChkSecurity");

typedef int (__stdcall * pICFUNC)(string login_name, string Passwd);

pICFUNC wrappedFunction;
wrappedFunction = pICFUNC(ProcessID);

int intMyReturnVal = wrappedFunction("ausername","apass");

FreeLibrary(hGetProcIDDLL);

return intMyReturnVal;
}


From .NET, I get a "System.AccessViolationException: Attempted to read or write protected memory" error. I took the above code and simply executed it; I get another AccessViolation exception. I'm not completely sure I've written the .dll properly, and I believe I have the proper permissions to the .dll, but I really don't know. Any help would be greatly appreciated. Thanks!!
Topic archived. No new replies allowed.