Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 115241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:59:17+00:00 2026-05-11T02:59:17+00:00

I’m porting an existing (mostly) cross-platform application to WinCE 4.2. The current entry point

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:59:17+00:00Added an answer on May 11, 2026 at 2:59 am

    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.

    int WINAPI WinMain( HINSTANCE hInstance,                     HINSTANCE hPrevInstance,                     LPTSTR    lpCmdLine,                     int       nCmdShow ) {   assert(lpCmdLine != NULL);    int argc = 1, ret = 0;   std::vector<char*>  args;    // Copy the entire array to a regular cstr   int cmdLineLen = _tcslen(lpCmdLine);   char *argv = new char[cmdLineLen];   wcstombs(argv,lpCmdLine,cmdLineLen);   args.push_back(&argv[0]);    // Replace spaces with nulls to effectively create array of cstr   for(int i=0; i<cmdLineLen; i++){     if(argv[i] == ' '){       argv[i] = '\0';       args.push_back(&argv[i+1]); // Keep track of the first char in each word       argc++;     }   }    // argv[argc] should be NULL.    args.push_back(NULL);    try{ // Run the program     ret = main(argc,&args[0]);   }   catch(...){     // TODO: Report error here. Commented code works OK for WinCE .NET     // delete argv;     // throw;      ret = -1;   }   delete argv;   return ret; } 

    Also, for those interested, running this at the command line

    >myprogam.exe -a shortargument -b -c 

    will put the following in lpCmdLine

    '-a shortargument -b -c' 

    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?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 148k
  • Answers 148k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use absolute positioning and set the top/right attributes. #control {… May 12, 2026 at 9:21 am
  • Editorial Team
    Editorial Team added an answer Why don't you just transform the key using something like… May 12, 2026 at 9:21 am
  • Editorial Team
    Editorial Team added an answer Is the data html or xhtml? For xhtml, load it… May 12, 2026 at 9:21 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.