Click here to Skip to main content
15,891,431 members

Calling a Mixed dll from c++ code

Revision 3
Hello everyone ,
I need your help again.
This time i cant manage to call exported function from mixed dll from c++ code
I will start from the function which i am trying to call
C++
extern "C" void __stdcall FunForExport(LPCSTR strInputFile, LPCSTR strOutputFile, LPCSTR strDebugLog)
{
	String^ stInputFile = gcnew String(strInputFile);
	String^ stOutputFile = gcnew String(strOutputFile);
	String^ stDebugLog = gcnew String(strDebugLog);
	EntryPointClass^ Text = gcnew EntryPointClass();
	
	Text->CalculateCoords(stDebugLog, false, stInputFile, stOutputFile);
}

The def file looks like this
LIBRARY		"SomeDllName"

EXPORTS
	FunForExport

The function pointer looks like this
C++
typedef void (CALLBACK* PFunForExport)(LPCSTR,LPCSTR, LPCSTR);

in the c++ code i am loading the dll with LoadLibrary()
C++
HMODULE hTheDll = LoadLibrary(TEXT(strdll)); //where the strdll keeps the full path of the dll and its name
...
PFunForExport pFunForExport = (PFunForExport)GetProcAddress(hTheDll, TEXT("FunForExport"));

and when i call the pointer this way the program crashes
hTheDll is not null
C++
pFunForExport((char*)strLogFile.GetString(), (char*)strInputFile.GetString(),(char*)strOutputFile.GetString());


EntryPointClass is declared in F# program which dll is added in the reference of the mixed dll
The error which is shown when the program crashes is

Unhandled exception at 0x771115de in TheProgram.exe: 0xE0434352: 0xe0434352.

but in Output window i can see this

CSS
First-chance exception at 0x7632b9bc in See_View_Tester.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x0241ccd8..
First-chance exception at 0x7632b9bc in TheExe.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
First-chance exception at 0x7632b9bc in TheExe.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
First-chance exception at 0x7632b9bc in TheExe.exe: 0xE0434352: 0xe0434352.
First-chance exception at 0x7632b9bc in TheExe.: Microsoft C++ exception: [rethrow] at memory location 0x00000000..


I noticed that when i use GetProcAddress the pointer keeps _FunForExport only and as far as i remember and understand it should be _FunForExport@12

Please help me figure it out. Why its crashing and what exactly isn't right

P.S Visual Studio 2010 is my compiler
Thank you in advance.
Posted 18-Sep-12 3:40am by Argonia.
Tags: , ,