本文整理汇总了C++中LoadLibraryExW函数的典型用法代码示例。如果您正苦于以下问题:C++ LoadLibraryExW函数的具体用法?C++ LoadLibraryExW怎么用?C++ LoadLibraryExW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadLibraryExW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _Py_CheckPython3
int
_Py_CheckPython3()
{
wchar_t py3path[MAXPATHLEN+1];
wchar_t *s;
if (python3_checked)
return hPython3 != NULL;
python3_checked = 1;
/* If there is a python3.dll next to the python3y.dll,
assume this is a build tree; use that DLL */
wcscpy(py3path, dllpath);
s = wcsrchr(py3path, L'\\');
if (!s)
s = py3path;
wcscpy(s, L"\\python3.dll");
hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (hPython3 != NULL)
return 1;
/* Check sys.prefix\DLLs\python3.dll */
wcscpy(py3path, Py_GetPrefix());
wcscat(py3path, L"\\DLLs\\python3.dll");
hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
return hPython3 != NULL;
}
示例2: PVOID
static void *_load_dll(const wchar_t *lib_path, const wchar_t *dll_search_path)
{
void *result;
typedef PVOID(WINAPI *AddDllDirectoryF) (PCWSTR);
typedef BOOL(WINAPI *RemoveDllDirectoryF)(PVOID);
AddDllDirectoryF pAddDllDirectory;
RemoveDllDirectoryF pRemoveDllDirectory;
pAddDllDirectory = (AddDllDirectoryF)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "AddDllDirectory");
pRemoveDllDirectory = (RemoveDllDirectoryF)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "RemoveDllDirectory");
if (pAddDllDirectory && pRemoveDllDirectory) {
result = LoadLibraryExW(lib_path, NULL,
LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!result) {
PVOID cookie = pAddDllDirectory(dll_search_path);
result = LoadLibraryExW(lib_path, NULL,
LOAD_LIBRARY_SEARCH_SYSTEM32 |
LOAD_LIBRARY_SEARCH_USER_DIRS);
pRemoveDllDirectory(cookie);
}
} else {
result = LoadLibraryW(lib_path);
if (!result) {
SetDllDirectoryW(dll_search_path);
result = LoadLibraryW(lib_path);
SetDllDirectoryW(L"");
}
}
return result;
}
示例3: LOG_ERROR
XAudio2Thread::XAudio2Thread()
{
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL))
{
LOG_ERROR(GENERAL, "XAudio: failed to increase thread priority");
}
if (auto lib2_9 = LoadLibraryExW(L"XAudio2_9.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
{
// xa28* implementation is fully compatible with library 2.9
xa28_init(lib2_9);
m_funcs.destroy = &xa28_destroy;
m_funcs.play = &xa28_play;
m_funcs.flush = &xa28_flush;
m_funcs.stop = &xa28_stop;
m_funcs.open = &xa28_open;
m_funcs.add = &xa28_add;
LOG_SUCCESS(GENERAL, "XAudio 2.9 initialized");
return;
}
if (auto lib2_7 = LoadLibraryExW(L"XAudio2_7.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
{
xa27_init(lib2_7);
m_funcs.destroy = &xa27_destroy;
m_funcs.play = &xa27_play;
m_funcs.flush = &xa27_flush;
m_funcs.stop = &xa27_stop;
m_funcs.open = &xa27_open;
m_funcs.add = &xa27_add;
LOG_SUCCESS(GENERAL, "XAudio 2.7 initialized");
return;
}
if (auto lib2_8 = LoadLibraryExW(L"XAudio2_8.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
{
xa28_init(lib2_8);
m_funcs.destroy = &xa28_destroy;
m_funcs.play = &xa28_play;
m_funcs.flush = &xa28_flush;
m_funcs.stop = &xa28_stop;
m_funcs.open = &xa28_open;
m_funcs.add = &xa28_add;
LOG_SUCCESS(GENERAL, "XAudio 2.8 initialized");
return;
}
fmt::throw_exception("No supported XAudio2 library found");
}
示例4: real_init
static void real_init(void) {
#ifdef VS_TARGET_OS_WINDOWS
// portable
const std::wstring pythonDllName = L"python37.dll";
HMODULE module;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&real_init, &module);
std::vector<wchar_t> pathBuf(65536);
GetModuleFileNameW(module, pathBuf.data(), (DWORD)pathBuf.size());
std::wstring dllPath = pathBuf.data();
dllPath.resize(dllPath.find_last_of('\\') + 1);
std::wstring portableFilePath = dllPath + L"portable.vs";
FILE *portableFile = _wfopen(portableFilePath.c_str(), L"rb");
bool isPortable = !!portableFile;
if (portableFile)
fclose(portableFile);
HMODULE pythonDll = nullptr;
if (isPortable) {
std::wstring pyPath = dllPath + L"\\" + pythonDllName;
pythonDll = LoadLibraryExW(pyPath.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
} else {
DWORD dwType = REG_SZ;
HKEY hKey = 0;
wchar_t value[1024];
DWORD valueLength = 1000;
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\VapourSynth", &hKey) != ERROR_SUCCESS)
return;
LSTATUS status = RegQueryValueExW(hKey, L"PythonPath", nullptr, &dwType, (LPBYTE)&value, &valueLength);
RegCloseKey(hKey);
if (status != ERROR_SUCCESS)
return;
std::wstring pyPath = value;
pyPath += L"\\" + pythonDllName;
pythonDll = LoadLibraryExW(pyPath.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
}
if (!pythonDll)
return;
#endif
int preInitialized = Py_IsInitialized();
if (!preInitialized)
Py_InitializeEx(0);
s = PyGILState_Ensure();
if (import_vapoursynth())
return;
if (vpy_initVSScript())
return;
ts = PyEval_SaveThread();
initialized = true;
}
示例5: GetFileName
bool Win32DllLoader::Load()
{
if (m_dllHandle != NULL)
return true;
CStdString strFileName = GetFileName();
CStdStringW strDllW;
g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(strFileName), strDllW);
m_dllHandle = LoadLibraryExW(strDllW.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (!m_dllHandle)
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, 0, (LPTSTR) &lpMsgBuf, 0, NULL );
CLog::Log(LOGERROR, "%s: Failed to load %s with error %d:%s", __FUNCTION__, CSpecialProtocol::TranslatePath(strFileName).c_str(), dw, lpMsgBuf);
LocalFree(lpMsgBuf);
return false;
}
// handle functions that the dll imports
if (NeedsHooking(strFileName.c_str()))
OverrideImports(strFileName);
else
bIsSystemDll = true;
return true;
}
示例6: PickIconDlg
BOOL WINAPI PickIconDlg(
HWND hwndOwner,
LPWSTR lpstrFile,
UINT nMaxFile,
INT* lpdwIconIndex)
{
HMODULE hLibrary;
int res;
PICK_ICON_CONTEXT IconContext;
hLibrary = LoadLibraryExW(lpstrFile, NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
IconContext.hLibrary = hLibrary;
IconContext.Index = *lpdwIconIndex;
wcscpy(IconContext.szName, lpstrFile);
res = DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_PICK_ICON), hwndOwner, PickIconProc, (LPARAM)&IconContext);
if (res)
{
wcscpy(lpstrFile, IconContext.szName);
*lpdwIconIndex = IconContext.Index;
}
FreeLibrary(hLibrary);
return res;
}
示例7: tt_dll_create_ntv
tt_result_t tt_dll_create_ntv(IN tt_dll_ntv_t *dll,
IN const tt_char_t *path,
IN OPT tt_dll_attr_t *attr)
{
void *handle;
DWORD dwFlags = 0;
wchar_t *w_path;
TT_ASSERT(dll != NULL);
TT_ASSERT(path != NULL);
// may set mode according to attr;
// dwFlags |= ...;
w_path = tt_wchar_create(path, 0, NULL);
if (w_path == NULL) {
return TT_FAIL;
}
handle = LoadLibraryExW(w_path, NULL, dwFlags);
tt_wchar_destroy(w_path);
if (handle == NULL) {
TT_ERROR_NTV("LoadLibraryExW failed: %s");
return TT_FAIL;
}
dll->handle = handle;
return TT_SUCCESS;
}
示例8: lock
void LOCATOR::SYMSRV::Init()
{
AutoLock lock(&m_cs);
if (m_fInit) {
return;
}
m_fInit = true;
PREFAST_SUPPRESS(6321, "It's ok");
HMODULE hmod = LoadLibraryExW(L"SYMSRV.DLL", NULL, 0);
if ((UINT_PTR) hmod < 32) {
return;
}
m_hmod = hmod;
m_pfnsymbolserverw =
PFNSYMBOLSERVERW(GetProcAddress(m_hmod, "SymbolServerW"));
m_pfnsymbolserversetoptions =
PFNSYMBOLSERVERSETOPTIONS(GetProcAddress(m_hmod, "SymbolServerSetOptions"));
m_pfnsymbolserverstorefilew =
PFNSYMBOLSERVERSTOREFILEW(GetProcAddress(m_hmod, "SymbolServerStoreFileW"));
}
示例9: LoadCoreClrFromPath
HMODULE LoadCoreClrFromPath(const std::wstring& coreclr_dir, dnx::trace_writer& trace_writer)
{
auto loader_module = LoadLoaderModule(trace_writer);
if (!loader_module)
{
trace_writer.write(L"Failed to load loader module", false);
return nullptr;
}
auto pfnAddDllDirectory = (FnAddDllDirectory)GetProcAddress(loader_module, "AddDllDirectory");
auto pfnSetDefaultDllDirectories = (FnSetDefaultDllDirectories)GetProcAddress(loader_module, "SetDefaultDllDirectories");
if (!pfnAddDllDirectory || !pfnSetDefaultDllDirectories)
{
trace_writer.write(std::wstring(L"Failed to find function: ")
.append(pfnAddDllDirectory ? L"SetDefaultDllDirectories" : L"AddDllDirectory"), false);
return nullptr;
}
pfnAddDllDirectory(coreclr_dir.c_str());
// Modify the default dll flags so that dependencies can be found in this path
pfnSetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_USER_DIRS);
return LoadLibraryExW(dnx::utils::path_combine(coreclr_dir, L"coreclr.dll").c_str(), NULL, 0);
}
示例10: pyi_utils_dlopen
/* Load the shared dynamic library (DLL) */
dylib_t pyi_utils_dlopen(const char *dllpath)
{
#ifdef _WIN32
wchar_t * dllpath_w;
dylib_t ret;
#else
int dlopenMode = RTLD_NOW | RTLD_GLOBAL;
#endif
#ifdef AIX
/* Append the RTLD_MEMBER to the open mode for 'dlopen()'
* in order to load shared object member from library.
*/
dlopenMode |= RTLD_MEMBER;
#endif
#ifdef _WIN32
dllpath_w = pyi_win32_utils_from_utf8(NULL, dllpath, 0);
ret = LoadLibraryExW(dllpath_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
free(dllpath_w);
return ret;
#else
return dlopen(dllpath, dlopenMode);
#endif
}
示例11: LoadLibraryW
/*
* @implemented
*/
HINSTANCE
WINAPI
LoadLibraryW(LPCWSTR lpLibFileName)
{
/* Call Ex version of the API */
return LoadLibraryExW (lpLibFileName, 0, 0);
}
示例12: file
/*
Load the Python DLL, either from the resource in the library file (if found),
or from the file system.
This function should also be used to get all the function pointers that
python3.c needs at once.
*/
HMODULE load_pythondll(void)
{
HMODULE hmod_pydll;
HANDLE hrsrc;
HMODULE hmod = LoadLibraryExW(libfilename, NULL, LOAD_LIBRARY_AS_DATAFILE);
// Try to locate pythonxy.dll as resource in the exe
hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), PYTHONDLL);
if (hrsrc) {
HGLOBAL hgbl;
DWORD size;
char *ptr;
hgbl = LoadResource(hmod, hrsrc);
size = SizeofResource(hmod, hrsrc);
ptr = LockResource(hgbl);
hmod_pydll = MyLoadLibrary(PYTHONDLL, ptr, NULL);
} else
/*
XXX We should probably call LoadLibraryEx with
LOAD_WITH_ALTERED_SEARCH_PATH so that really our own one is
used.
*/
hmod_pydll = LoadLibrary(PYTHONDLL);
FreeLibrary(hmod);
return hmod_pydll;
}
示例13: Java_com_kenai_jffi_Foreign_dlopen
/*
* Class: com_kenai_jffi_Foreign
* Method: dlopen
* Signature: (Ljava/lang/String;I)J
*/
JNIEXPORT jlong JNICALL
Java_com_kenai_jffi_Foreign_dlopen(JNIEnv* env, jobject self, jstring jPath, jint jFlags)
{
#ifdef _WIN32
wchar_t path[PATH_MAX];
getWideString(env, path, jstr, sizeof(path) / sizeof(path[0]));
return p2j(LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH));
#else
char path_[PATH_MAX];
const char* path = NULL; // Handle dlopen(NULL, flags);
int flags = 0;
#define F(x) (jFlags & com_kenai_jffi_Foreign_RTLD_##x) != 0 ? RTLD_##x : 0;
flags |= F(LAZY);
flags |= F(GLOBAL);
flags |= F(LOCAL);
flags |= F(NOW);
#undef F
#ifdef _AIX
flags |= RTLD_MEMBER; // Needed for AIX
#endif
if (jPath != NULL) {
path = path_;
getMultibyteString(env, path_, jPath, sizeof(path_));
}
return p2j(dl_open(path, flags));
#endif
}
示例14: LoadLibraryExW
int32_t CSystem::GetSystemVersionNum()
{
DWORD dwVersion = 0;
HMODULE hinstDLL = LoadLibraryExW(L"kernel32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
if (hinstDLL != NULL)
{
HRSRC hResInfo = FindResource(hinstDLL, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
if (hResInfo != NULL)
{
HGLOBAL hResData = LoadResource(hinstDLL, hResInfo);
if (hResData != NULL)
{
static const WCHAR wszVerInfo[] = L"VS_VERSION_INFO";
struct VS_VERSIONINFO {
WORD wLength;
WORD wValueLength;
WORD wType;
WCHAR szKey[ARRAYSIZE(wszVerInfo)];
VS_FIXEDFILEINFO Value;
WORD Children[];
} *lpVI = (struct VS_VERSIONINFO *)LockResource(hResData);
if ((lpVI != NULL) && (lstrcmpiW(lpVI->szKey, wszVerInfo) == 0) && (lpVI->wValueLength > 0))
{
dwVersion = lpVI->Value.dwFileVersionMS;
}
}
}
FreeLibrary(hinstDLL);
}
return dwVersion;
}
示例15: Java_org_gudy_azureus2_platform_win32_access_impl_AEWin32AccessInterface_testNativeAvailabilityW
JNIEXPORT jboolean JNICALL
Java_org_gudy_azureus2_platform_win32_access_impl_AEWin32AccessInterface_testNativeAvailabilityW(
JNIEnv *env,
jclass cla,
jstring _name )
{
WCHAR name[2048];
if ( !jstringToCharsW( env, _name, name, sizeof( name )-1)){
return( 0 );
}
HMODULE mod =
LoadLibraryExW(
name,
NULL,
LOAD_LIBRARY_AS_DATAFILE );
if ( mod == NULL ){
return( 0 );
}else{
FreeLibrary( mod );
return( 1 );
}
}