Microsoft (R) Library Manager Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. Creating library SQLITE.lib and object SQLITE.exp 聽 榪欐牱灝辨垚鍔熷湴鍒涘緩浜嗗湪WIN32紼嬪簭涓闂畇qlite鎵闇瑕佺殑搴?鍙互鐢ㄤ簬閾炬帴WIN32紼嬪簭. 聽聽聽 鍒版鎵鏈変嬌鐢╯qlite鐨勫噯澶囧伐浣滃凡鍛婄絼.鐜板湪鍦∕SVC6涓柊寤轟竴涓猈in32 Console Application宸ョ▼,鎶妔qlite.dll,sqlite.h鍜宻qlite.lib鏂囦歡澶嶅埗鍒板伐紼嬫枃浠跺す涓?鎶妔qlite.h鏂囦歡鍔犲叆鍒伴」 鐩腑,鐒跺悗鍦≒roject Setting鐨凩ink涓殑瀵硅薄搴撴ā鍧椾腑澧炲姞sqlite.lib鏂囦歡. 鎴栬卲roject->add to project->files錛岄夋嫨榪欎釜lib鏂囦歡 鐒跺悗淇敼鍔犲叆濡備笅浠g爜鍗沖彲:
void CDllTestDlg::OnBtnSubtract() { 聽聽聽聽// TODO: Add your control notification handler code here 聽聽聽聽CString str; 聽聽聽聽str.Format("5-3=%d",subtract(5,3)); 聽聽聽聽MessageBox(str); }
void CDllTestDlg::OnBtnOutput() { 聽聽聽聽// TODO: Add your control notification handler code here 聽聽聽聽Point pt; 聽聽聽聽pt.output(5,3); }涓嬮潰鍏蜂綋浠嬬粛鏄劇ず鍔犺澆 鏄劇ず鍔犺澆 VC++緙栬瘧鍣ㄥ湪緙栬瘧DLL鐨勬椂鍊欏嚱鏁頒細鍙戠敓鍚嶅瓧鏀圭紪錛涗富瑕佸湪闈濩++鐜涓氨涓嶈兘璇嗗埆 璇ュ嚱鏁頒簡錛屾墍浠ヨ繖閲屽簲璇ュ畾涔夋ā鍧楁枃浠剁被鍨婦EF錛屼富瑕佸氨鏂逛究浜嗛潪C++紼嬪簭鍙互璋冪敤 璇LL閲岄潰鐨勫嚱鏁? 鍐嶄嬌鐢ㄦ樉紺哄姞杞藉墠蹇呴』瑕佹敞鎰忕殑鏄悕瀛楃殑鏀圭紪闂錛屽洜涓哄啀鍔ㄦ佸姞杞戒腑鍚嶅瓧鏀圭紪鍚? 鍦ㄥ姞杞藉氨寰椾笉鍘熸潵鐨勫嚱鏁板悕瀛椾簡錛岃繖鏍峰姞杞藉氨浼氬け璐ャ備絾鏄彲浠ョ敤鍙﹀涓縐嶆柟娉曞姞 杞斤細MSDN涓婂GetProAddress涓殑絎簩涓弬鏁版槸榪欐牱璇存槑鐨凱ointer to a null-ter minated string that specifies the function or variable name, or the func tion's ordinal value.涔熷氨鏄鍙互浣跨敤鍑芥暟鐨勫簭鍙鋒潵璋冪敤璇ュ嚱鏁幫紝鍏蜂綋浣跨敤鏂規硶 鏄疨rocAdd = (MYPROC) GetProcAddress(hinstLib, MakeIntResource(i)); (i浠h〃 鍑芥暟鍦―LL涓殑搴忓彿錛屽彲浠ョ敤DUMPBIN宸ュ叿鏌ョ湅)錛屼絾鏄竴鑸殑閮戒笉鐢ㄨ繖縐嶈漿鎹㈠簭鍙風殑 鏂瑰紡鏉ュ彇寰楀嚱鏁扮殑鍦板潃錛屽洜涓鴻繖鏍烽潪甯哥殑涓嶇洿瑙傦紒涓嬮潰灝辯敤妯″潡瀹氫箟鏂囦歡錛圖EF錛夋潵 閬垮厤DLL涓嚱鏁扮殑鍚嶅瓧鐨勬敼緙栭棶棰?
鏄劇ず鍔犺澆DLL //MSDN涓婄殑瀵笵LL榪涚▼鏄劇ず鍔犺澆鐨凞EMO Using Run-Time Dynamic Linking You can use the same DLL in both load-time and run-time dynamic linking. The following example uses the LoadLibrary function to get a handle to the Myputs DLL (see Creating a Simple Dynamic-Link Library). If LoadLibr ary succeeds, the program uses the returned handle in the GetProcAddress function to get the address of the DLL's myPuts function. After calling the DLL function, the program calls the FreeLibrary function to unload the DLL. Because the program uses run-time dynamic linking, it is not necessary t o link the module with an import library for the DLL. This example illustrates an important difference between run-time and lo ad-time dynamic linking. If the DLL is not available, the application us ing load-time dynamic linking must simply terminate. The run-time dynami c linking example, however, can respond to the error. // A simple program that uses LoadLibrary and // GetProcAddress to access myPuts from Myputs.dll.
#include <stdio.h> #include <windows.h> typedef int (*MYPROC)(LPTSTR); VOID main(VOID) { 聽聽聽HINSTANCE hinstLib; 聽聽聽MYPROC ProcAdd; 聽聽聽BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 聽// Get a handle to the DLL module. hinstLib = LoadLibrary(TEXT("DllTest")); // If the handle is valid, try to get the function address. if (hinstLib != NULL) 聽聽聽{ 聽聽聽聽聽聽聽ProcAdd = (MYPROC) GetProcAddress(hinstLib, TEXT("Proc")); // If the function address is valid, call the function. 聽if (NULL != ProcAdd) 聽聽聽聽聽聽聽{ 聽聽聽聽聽聽聽聽聽聽聽fRunTimeLinkSuccess = TRUE; 聽聽聽聽聽聽聽聽聽聽聽(ProcAdd) (TEXT("Message via DLL function\n")); 聽聽聽聽聽聽聽} 聽// Free the DLL module. fFreeResult = FreeLibrary(hinstLib); 聽聽聽} 聽// If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) 聽聽聽聽聽聽printf("Message via alternative method\n"); }
瀵逛互涓婄殑鍑犱釜鍑芥暟浣滀竴浜涘繀瑕佺殑璇存槑錛? LoadLibrary錛氬姞杞芥寚瀹氱殑DLL錛屽姞杞芥柟寮忔槸鍏堝湪褰撳墠鐩綍涓煡鎵撅紝濡傛灉鎵句笉鍒板啀鍐? 鐜鍙橀噺鐩綍涓嬫煡鎵撅紱 榪樻槸鐪婱SDN涓婄殑璇存槑 The LoadLibrary function maps the specified executable module into the a ddress space of the calling process. HMODULE LoadLibrary( 聽LPCTSTR lpFileName ); Parameters lpFileName [in] Pointer to a null-terminated string that names the executable modul e (either a .dll or .exe file). The name specified is the file name of t he module and is not related to the name stored in the library module it self, as specified by the LIBRARY keyword in the module-definition (.def ) file.
GetProcAddress錛氭槸鍙栧緱宸茬煡鐨凞LL涓殑鍑芥暟錛岃繑鍥炴寚瀹氬嚱鏁扮殑鍦板潃 MSDN涓婄殑璇存槑 This function returns the address of the specified exported DLL function . FARPROC GetProcAddress( 聽HMODULE hModule, 聽LPCWSTR lpProcName ); Parameters hModule [in] Handle to the DLL module that contains the function. The LoadLibrary or GetModuleHandle function returns this handle. lpProcName [out] Pointer to a null-terminated string containing the function name, or specifies the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero. The lpProcName parameter must be in Unicode. Remark: The GetProcAddress function is used to retrieve addresses of exported fu nctions in DLLs. The spelling and case of the function name pointed to by lpProcName must be identical to that in the EXPORTS statement of the source DLL's modul e-definition (.def) file. The exported names of Win32 APIs might differ from the names you use whe n calling these functions in your code. This difference is hidden by mac ros used in the SDK header files.