📄 subject_21226.htm
字号:
<p>
序号:21226 发表者:萧佬 发表日期:2002-11-15 08:57:50
<br>主题:如何引用一个lib库?
<br>内容:rt,<BR>在project->setting->link->object/library modules加*.LIB好象没有什么用。<BR>而这个lib也没有什么.h文件。到底怎么样才 能用 哦 !大家告诉我。
<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-15 09:15:58
<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>
回复者:树爱兵 回复日期:2002-11-15 09:36:03
<br>内容:②打开菜单 Tools->Options,选Directories项,在Show directories for:<BR>下拉框Include files选项中加入本程序下的”Include”目录;<BR>下拉框Library files选项中加入本程序下的”Lib”目录。<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:41:00
<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>
<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 + -