我似乎無法通過這個錯誤,所以我想知道如果我在我的調用代碼或我的DLL做任何錯誤?從C#運行代碼錯誤的DLL#
-Error-
$exception {System.BadImageFormatException: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
-call代碼 -
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;
}
非常感謝,先生。 :> – CyanPrime 2013-03-04 21:42:45