Thursday, July 15, 2010

How to get parameters from command-line in MFC

after reviewing many method that I found such a override CommandLine Handling Class

But I think it should something easier finally I found. Thanks Google and Viorel from http://www.windows-tech.info/17/9c91f002ea72ac3d.php

>>>Here is one solution, using CommandLineToArgvW command

for MFC in class ....App there is function InitInstance() that will be called first when program start. Before line

INT_PTR nResponse = dlg.DoModal();

added code

LPWSTR *szArglist;
int nArgs;
int i;

szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if( NULL == szArglist )
{
wprintf(L"CommandLineToArgvW failed\n");
return 0;
}
else
{
for( i=0; i
{
printf("%d: %ws\n", i, szArglist[i]);
}
}

No comments:

Post a Comment