📄 subject_27296.htm
字号:
<p>
序号:27296 发表者:mkyong 发表日期:2003-01-10 09:13:36
<br>主题:DLL explicit dynaimic linking problem
<br>内容:when i click leftmouse, i got this message"Unable to locate the function", why i can't get the function address?<BR>i already put the mydll.dll file in the same folder and some PATH environment variable folder, but still can't working....<BR>please....<BR><BR>/***********mydll.cpp*****************/<BR><BR>#include<windows.h><BR>#include"mydll.h"<BR>void ShowMousePos(HDC hDC, LPARAM lParam)<BR>{<BR> char str[80];<BR> wsprintf(str,"Button position is %d, %d", LOWORD(lParam),HIWORD(lParam));<BR> TextOut(hDC,LOWORD(lParam),HIWORD(lParam),str,strlen(str));<BR>}<BR><BR>/******mydll.h************/<BR><BR>#define DllExport __declspec(dllexport)<BR>DllExport void ShowMousePos(HDC hDC,LPARAM lParam);<BR><BR><BR>/*******ExplicitDll.cpp( Win32 implement dll file)************/<BR><BR>long FAR PASCAL WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<BR>{<BR> HDC hDC;<BR> HMODULE hLibrary;<BR><BR> typedef void (*func)(HDC,LPARAM);<BR> func f;<BR> hLibrary = LoadLibrary("mydll");<BR> <BR> if(!hLibrary)<BR> {<BR> MessageBox(hwnd,"Cannot Load Library","Error",MB_OK);<BR> return 0;<BR> }<BR> switch(msg)<BR> {<BR> case WM_LBUTTONDOWN:<BR> hDC = GetDC(hwnd);<BR> f = (func) GetProcAddress(hLibrary, "ShowMousePos");<BR> if(!f)<BR> {<BR> MessageBox(hwnd,"Unable to locate the function","Error",MB_OK);<BR> return 0;<BR> }<BR> f(hDC,lParam);<BR> ReleaseDC(hwnd,hDC);<BR> case WM_DESTROY:<BR> FreeLibrary(hLibrary);<BR> PostQuitMessage(0);<BR> break;<BR> default:<BR> return DefWindowProc(hwnd,msg,wParam,lParam);<BR> }<BR> return 0;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:bb 回复日期:2003-01-10 09:34:56
<br>内容:应为hLibrary = LoadLibrary("mydll.dll");<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:mkyong 回复日期:2003-01-10 19:42:39
<br>内容:应为hLibrary = LoadLibrary("mydll.dll");<BR><BR>What means, can u explain more clearly. Thx
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tjhe 回复日期:2003-01-10 22:47:52
<br>内容:use full file name of the dll: hLibrary = LoadLibrary("mydll.dll");<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:mkyong 回复日期:2003-01-11 11:56:48
<br>内容:try already lah, still can't working.<BR>i think not the LoadLibrary() problem, coz i didn't get the<BR>"Cannot Load Library" Message.<BR><BR>i think may be GetProcAddress() problem coz i can't get the function address......<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:cool 回复日期:2003-01-13 11:46:07
<br>内容:#include<windows.h><BR>#include"mydll.h"<BR>extern "C" __declspec(dllexport) void ShowMousePos(HDC hDC, LPARAM lParam)<BR>^^^^^^^^^^^<BR>{<BR> char str[80];<BR> wsprintf(str,"Button position is %d, %d", LOWORD(lParam),HIWORD(lParam));<BR> TextOut(hDC,LOWORD(lParam),HIWORD(lParam),str,strlen(str));<BR>}<BR><BR>/******mydll.h************/<BR><BR>//#define DllExport __declspec(dllexport)<BR>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<BR>extern "C" __declspec(dllexport) void ShowMousePos(HDC hDC,LPARAM lParam);<BR>^^^^^^^^^^<BR><BR><BR><BR>/*******ExplicitDll.cpp( Win32 implement dll file)************/<BR><BR><BR>typedef void DLLFUNC(HDC,LPARAM);<BR>DLLFUNC *f;<BR>f = (DLLFUNC *) GetProcAddress(hLibrary, "ShowMousePos");<BR><BR>try it<BR><BR><BR><BR> <BR><BR><BR><BR>2003-1-13 15:35:56
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -