c++ - Command Line Argument Truncated by CreateprocessW -


vs10, mbcs, unicode preprocessor defs. having gone through dr google's casebook, best here, doesn't quite address particular problem. consider code thisexepath path executable:

cmdlinearg = (wchar_t *)calloc(biggerthanmaxpath, sizeof(wchar_t)); wcscpy_s (cmdlinearg, maxpathfolder, l"\\\\??\\c:\\my directory\\my directory\\"); createprocessw (thisexepath, cmdlinearg, null, null, false, null, null, null, &lpstartupinfo, &lpprocessinfo) 

when program called

int winapi wwinmain(hinstance hinstance, hinstance hprevinstance, lpwstr lpcmdline, int ncmdshow) { wchar_t hrtext[256]; swprintf_s(hrtext, sizeof(hrtext), l"%ls", lpcmdline); //deal possible buffer overflow later messageboxw(null, hrtext, l"display", mb_iconinformation); } 

hrtext displays "my directory\my directory\" obvious missed here?

this not correct:

wchar_t hrtext[256]; swprintf_s(hrtext, sizeof(hrtext), l"%ls", lpcmdline); 

the second parameter should denote number of characters, not bytes.

msdn link swprintf_s

it should this:

wchar_t hrtext[256]; swprintf_s(hrtext, sizeof(hrtext) / sizeof(wchar_t), l"%ls", lpcmdline); 

or simply:

wchar_t hrtext[256]; swprintf_s(hrtext, 256, l"%ls", lpcmdline); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -