- LPWSTR lpwSource;
- LPWSTR lpwExeName;
- LPWSTR lpwTargetBuffer;
- UINT dwSourceSize;
- UINT dwExeNameSize;
- UINT dwResult;
-
- DPRINT("GetConsoleAliasA entered\n");
-
- if (lpTargetBuffer == NULL)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
-
- dwSourceSize = (strlen(lpSource)+1) * sizeof(WCHAR);
- lpwSource = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSourceSize);
- if (lpwSource == NULL)
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
- MultiByteToWideChar(CP_ACP, 0, lpSource, -1, lpwSource, dwSourceSize);
-
- dwExeNameSize = (strlen(lpExeName)+1) * sizeof(WCHAR);
- lpwExeName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwExeNameSize);
- if (lpwExeName == NULL)
- {
- HeapFree(GetProcessHeap(), 0, lpwSource);
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
- MultiByteToWideChar(CP_ACP, 0, lpExeName, -1, lpwExeName, dwExeNameSize);
-
- lpwTargetBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, TargetBufferLength * sizeof(WCHAR));
- if (lpwTargetBuffer == NULL)
- {
- HeapFree(GetProcessHeap(), 0, lpwSource);
- HeapFree(GetProcessHeap(), 0, lpwExeName);
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
-
- dwResult = GetConsoleAliasW(lpwSource, lpwTargetBuffer, TargetBufferLength * sizeof(WCHAR), lpwExeName);
-
- HeapFree(GetProcessHeap(), 0, lpwSource);
- HeapFree(GetProcessHeap(), 0, lpwExeName);
-
- if (dwResult)
- dwResult = WideCharToMultiByte(CP_ACP, 0, lpwTargetBuffer, dwResult / sizeof(WCHAR), lpTargetBuffer, TargetBufferLength, NULL, NULL);
-
- HeapFree(GetProcessHeap(), 0, lpwTargetBuffer);
-
- return dwResult;