Click here to Skip to main content
15,908,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code and i want to use simple main like int main() is there anyway i can pass below int WINAPI WinMain() arguments from int main()
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)


What I have tried:

int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
Posted
Updated 18-Mar-20 11:57am
Comments
CPallini 18-Mar-20 17:46pm    
Could you please elaborate? What kind of code you have and why do you want to call WinMain in your code?
Member 12899279 19-Mar-20 13:12pm    
got it working thanks

The arguments for main are defined by standards:
int main(int argc, char* argv[])
argc is the size of the argv array, which contains a set of C strings (null terminated). The first string will be the path to the directory out of which the program was launched, ending with the name of the .exe file itself.

An implementation that allows you to invoke main or pass it different arguments would not be compliant with standards. I haven't used WinMain, but my guess is that your choices are to either use it or regular main.

It would be also useful to know what you're trying to achieve.
 
Share this answer
 
v3
Comments
Greg Utas 19-Mar-20 8:57am    
Unfortunately, I have no experience with WinMain and the other Windows-specific stuff in your code. And your code is neither formatted nor commented, so I doubt anyone will want to spend much time looking at it. It seems that both are similar, so I suggest that you step through each of them, line by line, with a debugger, to see where they behave differently.
Member 12899279 19-Mar-20 9:12am    
thanks i just read from somewhere on net that for security purpose it won't work if taskscheduler runs it...so only option left is to somehow pass these arguments which are in WinMain from main..but how i can still not think of any way as i don't really know what these parameter are doing
Generally speaking, WinMain is the standard entry point for a windows GUI program and main is the entry point for command-line interface (CLI) program. For a CLI program the only parameter of interest is lpCmdLine which is all of the arguments in one string. Normally the arguments are parsed out into separate strings and passed as an array to the main function along with the number of how many there are with the full path to the executable program in slot zero of the array as Greg mentioned.

The bottom line is you can't just pass the arguments along as you have asked. It will require some work to massage the arguments into a form that main can deal with. Besides that, normally one does not call main. If you think you really need to then you are likely to be operating under one misconception or another and you should reconsider your options.

If you are working with MFC you can still obtain the arguments in the argc,argv format like a CLI uses. If not, I don't think so. Regardless, I think it would be best if you modify your question to ask about what your intentions really are.
 
Share this answer
 
Comments
Rick York 19-Mar-20 10:56am    
I will repeat myself : "I think it would be best if you modify your question to ask about what your intentions really are." Remember to use the code tags around your code and indent it properly so people can read it easier.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900