⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_20683.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:20683 发表者:萧一郎 发表日期:2002-11-08 14:32:48
<br>主题:如何在VC中调用DLL动态库
<br>内容:我真的不知道怎么办?<BR>谢谢各位大侠!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:徐景周 回复日期:2002-11-08 15:01:17
<br>内容:to load dynamic link librarys the easiest way instead of the long way <BR><BR>Introduction<BR>Have you ever got tired of loading Dynamic Link Libraries the long way, with the usual steps LoadLibrary, and GetProcAddress, then you have to check for each function address if they are NULL, and don't mention about casting the function pointer and hard ways that make your brain strain. And wish there was an easier way to get around things? Well this will just do that in a way and is about the easiest way I know of actually<BR><BR><BR>//GetProcAddresses<BR>//Argument1: hLibrary - Handle for the Library Loaded<BR>//Argument2: lpszLibrary - Library to Load<BR>//Argument3: nCount - Number of functions to load<BR>//[Arguments Format]<BR>//Argument4: Function Address - Function address we want to store<BR>//Argument5: Function Name - Name of the function we want<BR>//[Repeat Format]<BR>//<BR>//Returns: FALSE if failure<BR>//Returns: TRUE if successful<BR>BOOL GetProcAddresses( HINSTANCE *hLibrary, <BR>LPCSTR lpszLibrary, INT nCount, ... )<BR>{<BR>va_list va;<BR>va_start( va, nCount );<BR><BR>if ( ( *hLibrary = LoadLibrary( lpszLibrary ) ) <BR>!= NULL )<BR>{<BR>FARPROC * lpfProcFunction = NULL;<BR>LPSTR lpszFuncName = NULL;<BR>INT nIdxCount = 0;<BR>while ( nIdxCount &lt; nCount )<BR>{<BR>lpfProcFunction = va_arg( va, FARPROC* );<BR>lpszFuncName = va_arg( va, LPSTR );<BR>if ( ( *lpfProcFunction = <BR>GetProcAddress( *hLibrary, <BR>lpszFuncName ) ) == NULL )<BR>{<BR>lpfProcFunction = NULL;<BR>return FALSE;<BR>}<BR>nIdxCount++;<BR>}<BR>}<BR>else<BR>{<BR>va_end( va );<BR>return FALSE;<BR>}<BR>va_end( va );<BR>return TRUE;<BR>}<BR><BR>So since we now have the main core to this article, lets now look at how to use this with a short sample that was compiled as a Windows console application.<BR><BR>#include <BR><BR>typedef int ( WINAPI *MESSAGEBOX ) <BR>( HWND , LPCSTR, LPCSTR, DWORD );<BR>typedef int ( WINAPI *MESSAGEBOXEX ) <BR>( HWND , LPCSTR, LPCSTR, DWORD , WORD );<BR><BR>void main(void)<BR>{<BR>MESSAGEBOX lpfMsgBox = NULL;<BR>MESSAGEBOXEX lpfMsgBoxEx = NULL;<BR>HINSTANCE hLib;<BR>if(GetProcAddresses( &hLib, "User32.dll", 2,<BR>&lpfMsgBox, "MessageBoxA",<BR>&lpfMsgBoxEx, "MessageBoxExA" ) )<BR>{<BR>lpfMsgBox( 0, "Test1", "Test1", MB_OK );<BR>lpfMsgBoxEx( 0, "Test2", "Test2", MB_OK, <BR>MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ) );<BR>}<BR>if ( hLib != NULL )<BR>FreeLibrary( hLib );<BR>}<BR><BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -