阅读:1210回复:3
【求助】关于动态连接库的调用
我用evc写了这样两段代码
dll的 #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { OutputDebugString( TEXT( "SModel Loaded\n") ); return TRUE; } __declspec(dllexport) void Event( HWND hWnd, UINT msg, DWORD lParam, DWORD wParam ) { MessageBox( hWnd, TEXT("Event Msg Received"), TEXT("Event"), MB_OK ); } 测试程序的 #include "stdafx.h" typedef void (*DllEvent)(HWND,UINT,DWORD,DWORD); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. DllEvent event; HMODULE hDLL = LoadLibrary( TEXT("SModel") ); if( hDLL == NULL ) { OutputDebugString( TEXT("failed in loading dll\n") ); return -1; } event = (DllEvent)GetProcAddress( hDLL, L"Event" ); if( event == NULL ) { OutputDebugString( TEXT("failed in loading function\n") ); FreeLibrary( hDLL ); return -1; } else { OutputDebugString( TEXT("function loaded\n") ); event( NULL, 0, 0, 0 ); } return 0; } 将dll上传到wince的模拟器以后在运行测试程序,总是显示方法装载错误。到底是为什么?求高手指点。 |
|
沙发#
发布于:2004-06-10 23:06
event = (DllEvent)GetProcAddress( hDLL, L"Event" );
不能用L,改成_T试试 |
|
板凳#
发布于:2004-06-11 17:34
我实验发现只要改成
extern "C" __declspec(dllexport) void Event( HWND hWnd, UINT msg, DWORD lParam, DWORD wParam ) 就行了 |
|
地板#
发布于:2004-06-13 07:35
我记得,如果不加 extern "C" 这句话,它是按照C++来调用的,在DLL里面好像对函数名会有改动,如果加了extern "C",就不会把函数名改掉,所以就能够调用
|
|