@@ -42,6 +42,7 @@ OBJC_EXPORT void *objc_destructInstance(id obj);
42
42
43
43
#if TARGET_OS_WIN32
44
44
#include <Shellapi.h>
45
+ #include <pathcch.h>
45
46
#endif
46
47
47
48
enum {
@@ -1321,33 +1322,24 @@ CF_PRIVATE void __CFSocketCleanup(void);
1321
1322
CF_PRIVATE void __CFStreamCleanup (void );
1322
1323
1323
1324
static CFBundleRef RegisterCoreFoundationBundle (void ) {
1324
- #ifdef _DEBUG
1325
- // might be nice to get this from the project file at some point
1326
- wchar_t * DLLFileName = (wchar_t * )L"CoreFoundation_debug.dll" ;
1327
- #else
1328
- wchar_t * DLLFileName = (wchar_t * )L"CoreFoundation.dll" ;
1329
- #endif
1330
1325
wchar_t path [MAX_PATH + 1 ];
1331
1326
path [0 ] = path [1 ] = 0 ;
1332
1327
DWORD wResult ;
1333
1328
CFIndex idx ;
1334
- HMODULE ourModule = GetModuleHandleW (DLLFileName );
1335
1329
1336
- CFAssert (ourModule , __kCFLogAssertion , "GetModuleHandle failed" );
1330
+ HMODULE ourModule = NULL ;
1331
+ GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT ,
1332
+ (LPCWSTR )& RegisterCoreFoundationBundle , & ourModule );
1333
+ CFAssert (ourModule , __kCFLogAssertion , "GetModuleHandleExW failed" );
1337
1334
1338
1335
wResult = GetModuleFileNameW (ourModule , path , MAX_PATH + 1 );
1339
1336
CFAssert1 (wResult > 0 , __kCFLogAssertion , "GetModuleFileName failed: %d" , GetLastError ());
1340
1337
CFAssert1 (wResult < MAX_PATH + 1 , __kCFLogAssertion , "GetModuleFileName result truncated: %s" , path );
1341
1338
1342
1339
// strip off last component, the DLL name
1343
- for (idx = wResult - 1 ; idx ; idx -- ) {
1344
- if ('\\' == path [idx ]) {
1345
- path [idx ] = '\0' ;
1346
- break ;
1347
- }
1348
- }
1340
+ PathCchRemoveFileSpec (path , wResult );
1349
1341
1350
- CFStringRef fsPath = CFStringCreateWithCharacters (kCFAllocatorSystemDefault , (UniChar * )path , idx );
1342
+ CFStringRef fsPath = CFStringCreateWithCharacters (kCFAllocatorSystemDefault , (UniChar * )path , wcslen ( path ) );
1351
1343
CFURLRef dllURL = CFURLCreateWithFileSystemPath (kCFAllocatorSystemDefault , fsPath , kCFURLWindowsPathStyle , TRUE);
1352
1344
CFURLRef bundleURL = CFURLCreateCopyAppendingPathComponent (kCFAllocatorSystemDefault , dllURL , CFSTR ("CoreFoundation.resources" ), TRUE);
1353
1345
CFRelease (fsPath );
0 commit comments