DLL檔案位于專案根目錄下,結構如下
~/DLL --DLL主檔案夾
-dir1 --DLL分檔案夾1
-dir2 --DLL分檔案夾1
-dir3 --DLL分檔案夾1
. --DLL檔案及其他檔案,主入口dll檔案在這里
.
.
/INCLUDE --頭檔案夾
/LIB --lib檔案夾
存在關聯DLL,現在需要使用vc6 呼叫,要求采用相對路徑,各位大神知道怎么弄么?剛接觸JNI不久。謝謝
uj5u.com熱心網友回復:
可以先獲取程式的絕對路徑再加上檔案夾名形成呼叫路徑uj5u.com熱心網友回復:
VC 6 里面可以添加LIb 還有h檔案然后編譯后 放入相關DLL即可
uj5u.com熱心網友回復:
相對路徑 就顯示鏈接 LoadLibrary GetProcAddress FreeLibraryuj5u.com熱心網友回復:
獲取程式的絕對路徑再加上相應dll檔案夾名形成呼叫路徑,使用LoadLibrary的方式uj5u.com熱心網友回復:
由于是第三方提供的dll檔案 所以他們說LoadLibrary這種方式是不行的
只能使用隱式呼叫。
uj5u.com熱心網友回復:
我的專案目錄結構是release中放入DLL檔案夾,里面還有子檔案夾放DLL檔案。這種能行么
uj5u.com熱心網友回復:
DLL需要放到EXE能夠加載的位置,一般EXE所在的目錄是預設加載目錄,子檔案夾目錄會找不到加載的DLLuj5u.com熱心網友回復:
那就試試 用 GetEnvironmentVariable 和 SetEnvironmentVariable 把DLL 路徑添加到 "path" 環境變數中uj5u.com熱心網友回復:
Platform SDK: DLLs, Processes, and Threads
Dynamic-Link Library Search Order
Starting with Windows XP, the dynamic-link library (DLL) search order used by the system depends on the setting of the HKLM\System\CurrentControlSet\Control\Session Manager\SafeDllSearchMode value.
Windows Server 2003: The default value is 1.
Windows XP: The default value is 0.
If SafeDllSearchMode is 1, the search order is as follows:
The directory from which the application loaded.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The current directory.
The directories that are listed in the PATH environment variable.
If SafeDllSearchMode is 0, the search order is as follows:
The directory from which the application loaded.
The current directory.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable.
Alternate Search Order
The LoadLibraryEx function supports an alternate search order if the call specifies LOAD_WITH_ALTERED_SEARCH_PATH and the lpFileName parameter specifies a path. If SafeDllSearchMode is 1, the alternate search order is as follows:
The directory specified by lpFileName.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The current directory.
The directories that are listed in the PATH environment variable.
If SafeDllSearchMode is 0, the alternate search order is as follows:
The directory specified by lpFileName.
The current directory.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable.
Note that the standard search strategy and the alternate search strategy differ in just one way: the standard search begins in the calling application's directory, and the alternate search begins in the directory of the executable module that LoadLibraryEx is loading.
If you specify the alternate search strategy, its behavior continues until all associated executable modules have been located. After the system starts processing DLL initialization routines, the system reverts to the standard search strategy.
Legacy Search Order
Earlier versions of Windows do not support the SafeDllSearchMode value. The DLL search order is as follows.
Windows 2000/NT: The system searches for DLLs in the following order:
The directory from which the application loaded.
The current directory.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable.
Windows Me/98/95: The system searches for DLLs in the following order:
The directory from which the application loaded.
The current directory.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable.
--------------------------------------------------------------------------------
Last updated: March 2005 | What did you think of this topic? | Order a Platform SDK CD
? Microsoft Corporation. All rights reserved. Terms of use.
uj5u.com熱心網友回復:
GetModuleFileName()然后自己拼裝成絕對路徑~uj5u.com熱心網友回復:
可以的 你構建絕對路徑的時候寫上就可以
uj5u.com熱心網友回復:
由于是第三方提供的dll檔案 所以LoadLibrary GetProcAddress FreeLibrary顯示鏈接方式是不行的只能使用如下隱式呼叫
#include "..\INCLUDE\xxx.h"
Link->Category/General->Object/library modeules添加 ..\LIB\dir1\*.lib或者在使用的檔案中#pragma comment(lib, "..\LIB\*.lib")
Post-build step里面添加如下命令 copy ..\DLL\dir1\*.dll .\Debug copy ..\DLL\dir2\*.dll .\Debug copy ..\DLL\dir3\*.dll .\Debug
or copy ..\DLL\dir1\*.dll .\Release copy ..\DLL\dir2\*.dll .\Release copy ..\DLL\dir3\*.dll .\Release
uj5u.com熱心網友回復:
放到exe路徑下,拼裝dll的路徑
WCHAR currentDir[MAX_PATH]= {0};
int ErrorCode = GetModuleFileNameW(NULL, currentDir, MAX_PATH); //獲取當前行程路徑
if(!ErrorCode)
{
return GetLastError();
}
wstring tempDir = currentDir;
wstring::size_type pos(0);
pos = tempDir.rfind(L"\\");
tempDir.replace(pos+1, 18, L"HookDll.dll"); //拼接DLL路徑
HINSTANCE hDll = LoadLibrary(tempDir.c_str());
cout << hDll << endl;
uj5u.com熱心網友回復:
SetDllDirectory把你的 dll 路徑加入,就可以直接使用了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/147869.html
標籤:進程/線程/DLL
下一篇:求幫助!怎么能先用(MM_HIMETRIC)模式畫出1:200的一條豎線。然后再用MM_ANISOTROPIC可以調節大小
