New uninstaller

Dmitry Timoshkov dmitry at baikal.ru
Tue Mar 8 04:04:56 CST 2005


"Jonathan Ernst" <Jonathan at ErnstFamily.ch> wrote:

> I tried to fix every char->WCHAR I though was worth it; please have a
> second look at it.
> 
> The problem now with unicode is that when I try to strstr my token with
> the element of the list (entries[i].descr) it works only with the first
> letter (before to use unicode it was working very well).
> You can see the same problem (one letter .descr) when using the
> unintaller with --list.
> 
> The second problem is that since I use unicode for the argvs, whatever
> argv I give I get the --list branch.

Your main mistake is that you are trying to handle ASCII strings with "old"
APIs, you can't do that. Unicode requires a completely different set of APIs,
and win32 provides one.

> +        /*
> +        TELL ME: IS IT STILL NEEDED WITH UNICODE ???
>          len = WideCharToMultiByte(CP_UNIXCP, 0, entries[i].descr, -1, NULL, 0, NULL, NULL); 

As I have said it already, you need to convert unicode strings to the encoding
of the underlying system before printing strings on console. CP_UNIXCP is supposed
to do exactly that task.

> +        descr = HeapAlloc(GetProcessHeap(), 0, len);
> +        WideCharToMultiByte(CP_UNIXCP, 0, entries[i].descr, -1, descr, len, NULL, NULL); */
> +        printf("%s|||%s\n", entries[i].key, entries[i].descr);
> +        /*HeapFree(GetProcessHeap(), 0, descr);*/

You have to HeapFree a HeapAlloc'ed memory block.

It's better to use W versions of APIs even if it's not strictly required.

> +    if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGSTR_PATH_UNINSTALL, 0, KEY_READ, &hkeyUninst) != ERROR_SUCCESS)

RegOpenKeyExW in this case.

>      {
> - MessageBox(0, "Uninstall registry key not available (yet), nothing to do !", appname, MB_OK);
> - return 0;
> +        MessageBox(0, sRegistryKeyNotAvailable, sAppName, MB_OK);

MessageBoxW in this case.

>      if (!entries)
> - entries = HeapAlloc(GetProcessHeap(), 0, sizeof(uninst_entry));
> +    entries = HeapAlloc(GetProcessHeap(), 0, sizeof(uninst_entry));

Quite strange formatting.

>      strcpy(key_app, REGSTR_PATH_UNINSTALL);
>      strcat(key_app, "\\");
>      p = key_app+strlen(REGSTR_PATH_UNINSTALL)+1;

You shouldn't use string APIs supposed to handle ASCII strings. Use lstrcpyW,lstrcatW
and lstrlenW in this and all other cases.
 
     sizeOfSubKeyName = 255;
-    for ( i=0;
-   RegEnumKeyExA( hkeyUninst, i, subKeyName, &sizeOfSubKeyName,
-      NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS;
-   ++i )
+    for (i=0; RegEnumKeyExA( hkeyUninst, i, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS; ++i)

RegEnumKeyExW in this case.

> +        static const WCHAR DisplayNameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
> +        strcpy(p, subKeyName);

lstrcpyW

> +        RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_app, 0, KEY_READ, &hkeyApp);

RegOpenKeyExW

> +        res = CreateProcess(NULL, entries[i].command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &info);

CreateProcessW

> +        prevsel = SendMessage(hList, LB_GETCURSEL, 0, 0);

SendMessageW

and many,many,many others. Make sure to pass correct arguments to all the changed APIs.

For better understanding of what is going on add the following as the very first
line in main.c:

#define __WINESRC__

-- 
Dmitry.




More information about the wine-devel mailing list