+#if defined(__WIN32__)
+// Returns the path to the CF DLL, which we can then use to find resources like char sets
+
+__private_extern__ const char *_CFDLLPath(void) {
+ static TCHAR cachedPath[MAX_PATH+1] = "";
+
+ if ('\0' == cachedPath[0]) {
+#if defined(DEBUG)
+ char *DLLFileName = "CoreFoundation_debug";
+#elif defined(PROFILE)
+ char *DLLFileName = "CoreFoundation_profile";
+#else
+ char *DLLFileName = "CoreFoundation";
+#endif
+ HMODULE ourModule = GetModuleHandle(DLLFileName);
+ CFAssert(ourModule, __kCFLogAssertion, "GetModuleHandle failed");
+
+ DWORD wResult = GetModuleFileName(ourModule, cachedPath, MAX_PATH+1);
+ CFAssert1(wResult > 0, __kCFLogAssertion, "GetModuleFileName failed: %d", GetLastError());
+ CFAssert1(wResult < MAX_PATH+1, __kCFLogAssertion, "GetModuleFileName result truncated: %s", cachedPath);
+
+ // strip off last component, the DLL name
+ CFIndex idx;
+ for (idx = wResult - 1; idx; idx--) {
+ if ('\\' == cachedPath[idx]) {
+ cachedPath[idx] = '\0';
+ break;
+ }
+ }
+ }
+ return cachedPath;
+}
+#endif
+