[MPlayer-dev-eng] [PATCH] Implement a few Unicode versions of Win32 functions
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sun Mar 7 00:01:27 CET 2010
On Sat, Mar 06, 2010 at 03:18:30PM +0100, Steinar H. Gunderson wrote:
> On Sat, Mar 06, 2010 at 02:46:17PM +0100, Steinar H. Gunderson wrote:
> > Implement GetVersionExW with the same data as GetVersionExA but taking in a
> > different structure, and CreateMutexW, CreateEventW and CreateSemaphoreW as
> > simple wrappers around the A versions.
>
> I realized these should probably handle a NULL name parameter as well.
> Updated version attached.
Well, maybe the WideCharToMultiByte function is the better choice
(though I consider it a bit of a too complex function for my tastes),
but I had this patch lying around:
Index: loader/win32.c
===================================================================
--- loader/win32.c (revision 30856)
+++ loader/win32.c (working copy)
@@ -614,16 +615,30 @@
return result;
}
-static HMODULE WINAPI expGetModuleHandleW(const uint16_t* name)
+/**
+ * Convert a wide-character ASCII string to a "normal" one.
+ * \param dst destination for string, set to empty string on error.
+ * \param dst_size size of dst buffer, must be at least 1.
+ * \return NULL if an error occured, dst otherwise
+ */
+static char *wtoa(char *dst, int dst_size, const uint16_t *src)
{
- char aname[256];
int pos = 0;
- while (*name) {
- if (*name > 256 || pos >= sizeof(aname) - 1)
+ dst[0] = 0;
+ while (*src) {
+ if (*src > 256 || pos >= dst_size - 1)
return NULL;
- aname[pos++] = *name++;
+ dst[pos++] = *src++;
}
- aname[pos] = 0;
+ dst[pos] = 0;
+ return dst;
+}
+
+static HMODULE WINAPI expGetModuleHandleW(const uint16_t* name)
+{
+ char aname[256];
+ if (!wtoa(aname, sizeof(aname), name))
+ return 0;
return expGetModuleHandleA(aname);
}
> +static void* WINAPI expCreateEventW(void* pSecAttr, char bManualReset,
> + char bInitialState, const WCHAR* name)
> +{
> + if (name) {
> + char ascii_name[256];
> + WideCharToMultiByte(65001, 0x0, name, -1, ascii_name, 256, NULL, NULL);
sizeof(ascii_name)
> + return expCreateEventA(pSecAttr, bManualReset, bInitialState, ascii_name);
> + } else {
> + return expCreateEventA(pSecAttr, bManualReset, bInitialState, NULL);
I don't like the duplication, something like
char ascii_name[256];
char *aname = NULL;
if (name) {
WideCharToMultiByte()
aname = ascii_name;
}
expCreateEventA()
Seems preferable to me.
More information about the MPlayer-dev-eng
mailing list