我似乎无法克服这个错误,所以我想知道我的调用代码或我的 DLL 是否做错了什么?
-错误-
$exception {System.BadImageFormatException: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
-呼叫代码-
Assembly assembly = Assembly.LoadFile(@"C:\Users\Admin\Documents\Visual Studio 2012\Projects\MyDLL\Release\myDLL.dll");
Type type = assembly.GetType("HelloWorld");
var obj = Activator.CreateInstance(type);
// Alternately you could get the MethodInfo for the TestRunner.Run method
type.InvokeMember("HelloWorld",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
obj,
null);
-DLL 代码-
#include <Windows.h>
using namespace std;
extern "C" _declspec(dllexport) void __stdcall HelloWorld(LPSTR title, LPSTR msg)
{
MessageBox( NULL, msg, title, MB_OK);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}