The following line is generating a runtime error in a C# GUI:
int x = myclass.number_from_dll();
I'm using Microsoft Visual Studio 2008.
The code in C# is:
class myclass
{
[DllImport("strat_gr_dll.dll", EntryPoint = "number_from_dll")]
public static extern int number_from_dll();
}
The code in the C++ .dll is:
开发者_JAVA百科// This is an example of an exported function.
DLL int number_from_dll(void)
{
return 42;
}
The runtime error from .NET is:
An attempt was made to load a program with an incorrect format.
(Exception from HRESULT: 0x8007000B)
Project + Properties, Build tab, Platform Target = x86.
Your C/C++ DLL was compiled in 32-bit mode. But your C# program is running on a 64-bit version of Windows and will run in 64-bit mode. That mix don't match. Creating a 64-bit version of you DLL is another solution. Build + Configuration Manager, Platform combo, New, x64.
精彩评论