I'm porting an existing (mostly) cross-platform application to WinCE 4.2. The current entry point for the function is
int main(int argc, char *argv[]){}
I would like to keep this part as-is, and have the WinCE entry point simply call it. I believe something like the following should work:
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
int argc = _tcslen(lpCmdLine);
char *argv = new char[argc];
wcstombs(argv,lpCmdLine,1024);
argc = main(argc,&argv);
delete [] argv;
return argc;
}
It compiles, and should run once I figure out why the linker is throwing up, but is it right?
Thank you both for your helpful answers. I wrote the following, which works as well as we need it for now. Only our code will be calling this executable, and never with quotes, although that wouldn't be too hard to add. Also, it might not do well if there is more than one space between arguments, but again, we don't have to worry about other people using this program, it's just for academic purposes. If you think improvements are necessary, edit this post, and justify it in your comment.
Also, for those interested, running this at the command line
will put the following in lpCmdLine
Also, my first guess was that argv needed to be delete[]'d (because I new char[]'d), but when I did this, the program had a fatal error. When I switched to the above, it worked. Doesn't that violate the new->delete/new[]->delete[] rule?