-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly converting the command line arguments of the VM
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,51 @@ | ||
#include "pharovm/pharoClient.h" | ||
|
||
#include <windows.h> | ||
#include <shellapi.h> | ||
|
||
int CALLBACK | ||
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | ||
{ | ||
return vm_main(__argc, (const char **)__argv, (const char**)environ); | ||
|
||
char **argsInUtf8 = NULL; | ||
LPWSTR *wideArgs; | ||
int numberOfArgs; | ||
int totalSize = 0; | ||
char *currentString; | ||
int *sizes; | ||
int i; | ||
|
||
/* | ||
Converting the arguments from wide char strings to UTF8 strings. | ||
*/ | ||
|
||
wideArgs = CommandLineToArgvW(GetCommandLineW(), &numberOfArgs); | ||
if( NULL == wideArgs ) | ||
{ | ||
logErrorFromGetLastError("CommandLineToArgvW failed"); | ||
return 0; | ||
} | ||
|
||
sizes = (int*)malloc(sizeof(int)*numberOfArgs); | ||
|
||
for( i=0; i<numberOfArgs; i++){ | ||
sizes[i] = WideCharToMultiByte(CP_UTF8, 0, wideArgs[i], -1, NULL, 0, NULL, FALSE); | ||
totalSize += sizes[i]; | ||
} | ||
|
||
totalSize += sizeof(char*) * numberOfArgs; | ||
argsInUtf8 = malloc(totalSize); | ||
|
||
currentString = &argsInUtf8[numberOfArgs]; | ||
|
||
for( i=0; i<numberOfArgs; i++){ | ||
argsInUtf8[i] = currentString; | ||
WideCharToMultiByte(CP_UTF8, 0, wideArgs[i], -1, currentString, sizes[i], NULL, FALSE); | ||
currentString = currentString + sizes[i]; | ||
} | ||
|
||
LocalFree(wideArgs); | ||
free((void*)sizes); | ||
|
||
return vm_main(numberOfArgs, (const char **)argsInUtf8, (const char**)environ); | ||
} |