📄 subject_21230.htm
字号:
<p>
序号:21230 发表者:萧佬 发表日期:2002-11-15 09:18:13
<br>主题:如何调用lib库函数
<br>内容:rt,lib没有.h文件,在program-setting-link-object/library modules中申明也没有用,
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:CDMA2000 回复日期:2002-11-15 09:22:17
<br>内容:那用LoadLibaray()来加载动态链接库!<BR>这样不需要LIB也不需要头文件
<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>回复者:徐景周 回复日期:2002-11-15 09:41:26
<br>内容:参看:<BR>可采用类似:<BR>#include <MMSystem.h><BR><BR>//#include <afxsock.h> // MFC socket extensions<BR>//#include <ras.h><BR>// CG: The following line was added by the Windows Multimedia component.<BR>#pragma comment(lib, "winmm.lib")<BR><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 < 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>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:崔明亮 回复日期:2002-11-15 09:48:08
<br>内容:#pragma comment(lib, "*.lib") , *.lib为您想要使用的库的名称,就像上面说的一样
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:关尔 回复日期:2003-01-22 15:54:39
<br>内容:在.NET里也可以这样?
<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 + -