Changeset 21673


Ignore:
Timestamp:
Jul 22, 2011, 12:47:57 AM (14 years ago)
Author:
dmik
Message:

CreateProcessA: Add support for CREATE_UNICODE_ENVIRONMENT.

This also fixes CreateProcessW calls which didn't handle the environment properly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/kernel32/wprocess.cpp

    r21669 r21673  
    23822382
    23832383    if(lpEnvironment) {
    2384         newenv = CreateNewEnvironment((char *)lpEnvironment);
     2384        char *envA = (char *)lpEnvironment;
     2385        if(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT) {
     2386            // process the CREATE_UNICODE_ENVIRONMENT on our own --
     2387            // O32_CreateProcessA() is not aware of it
     2388            dwCreationFlags &= ~CREATE_UNICODE_ENVIRONMENT;
     2389
     2390            WCHAR *tmp = (WCHAR *)lpEnvironment;
     2391            int sizeW = 0;
     2392            while (*tmp) {
     2393                int lenW = lstrlenW(tmp);
     2394                sizeW += lenW + 1;
     2395                tmp += lenW + 1;
     2396            }
     2397            sizeW++; // terminating null
     2398            int sizeA = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)lpEnvironment, sizeW,
     2399                                            NULL, 0, 0, NULL);
     2400            envA = (char *)malloc(sizeA);
     2401            if(envA == NULL) {
     2402                SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     2403                rc = FALSE;
     2404                goto finished;
     2405            }
     2406            WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)lpEnvironment, sizeW,
     2407                                envA, sizeA, 0, NULL);
     2408        }
     2409        newenv = CreateNewEnvironment(envA);
     2410        if(envA != (char *)lpEnvironment)
     2411            free(envA);
    23852412        if(newenv == NULL) {
    23862413            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     
    26252652    if(lpCurrentDirectory)
    26262653        astring3 = UnicodeToAsciiString((LPWSTR)lpCurrentDirectory);
     2654    if(lpEnvironment) {
     2655        // use a special flag instead of converting the environment here
     2656        dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
     2657    }
    26272658    rc = CreateProcessA(astring1, astring2, lpProcessAttributes, lpThreadAttributes,
    26282659                        bInheritHandles, dwCreationFlags, lpEnvironment,
Note: See TracChangeset for help on using the changeset viewer.