Skip to content

Commit 32597d6

Browse files
committed
fix vice_dynlib_ (windows) functions for unicode builds, patch by Carlo Bramini
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45864 379a1393-f5fb-40a0-bcee-ef074d9b53f7
1 parent 2e294a0 commit 32597d6

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

vice/src/arch/shared/dynlib-win32.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,57 @@ void archdep_opencbm_fix_dll_path(void)
9494
opencbm_fix_tried = 1;
9595
}
9696

97+
#ifdef _UNICODE
98+
static const WCHAR *alloc_wchar_from_char(const char *text)
99+
{
100+
int len;
101+
WCHAR *wtext;
102+
103+
/* Calculate required length (uses CP_ACP scheme) */
104+
len = MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
105+
106+
/* Get the space for the converted string */
107+
wtext = (WCHAR *)malloc(len * sizeof(WCHAR));
108+
if (wtext == NULL)
109+
return NULL;
110+
111+
/* Convert the string to WCHAR */
112+
MultiByteToWideChar(CP_ACP, 0, text, -1, wtext, len);
113+
114+
return wtext;
115+
}
116+
#endif
117+
97118
void *vice_dynlib_open(const char *name)
98119
{
99-
return LoadLibrary(TEXT(name));
120+
#ifdef _UNICODE
121+
WCHAR *wname = alloc_wchar_from_char(name);
122+
/* No need to test the value of wname, LoadLibrary()
123+
returns NULL if the parameter is also NULL. */
124+
HMODULE handle = LoadLibrary(wname);
125+
/* Free the allocated file name */
126+
free(wname);
127+
128+
return (void *)handle;
129+
#else
130+
return LoadLibrary(name);
131+
#endif
100132
}
101133

102134
void *vice_dynlib_symbol(void *handle,const char *name)
103135
{
136+
/* Windows CE has a sligthly different handling because
137+
the name of the exported function is also unicode */
138+
#ifdef _WIN32_WCE
139+
WCHAR *wname = alloc_wchar_from_char(name);
140+
void *address = GetProcAddress((HMODULE)handle, wname);
141+
/* Free the allocated file name */
142+
free(wname);
143+
144+
return address;
145+
#else
104146
return GetProcAddress((HMODULE)handle, name);
147+
#endif
105148
}
106149

107150
char *vice_dynlib_error(void)

0 commit comments

Comments
 (0)