parameters to windows exe

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Cogman

Lifer
Sep 19, 2000
10,284
138
106
Not a forced error, VS was expecting a stdcall function WinMain that accepts 16 bytes of information in the compilation somewhere (or linked in, but you don't link in win main, or shouldn't).

That is pretty standard behavior actually, try compiling and linking a console program without a main, and you'll get the same error. The linker must know where to enter the code.

Your winmain proc should look like this

Code:
int WINAPI WinMain(      
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)

So wherever you have your main(), replace it with this and things should work out (well, you'll have to change the argument handling thing a bit.
 
May 11, 2008
22,175
1,402
126
Hello, thank you for answering. :)

But unfortunately my winmain already looks like that.
Well to be honest, when i start a new project(windows application NOT a console application) this is what VS creates :

Code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

This is from my original code made with borland:
This code just generates errors...
Code:
int WINAPI WinMain (HINSTANCE hInstance, 
HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)

I have changed the VScode to winmain before, i know what you mean, i read about it this morning while googling for an answer but there is no relief. It just causes more errors when i change the code to the standard winmain.

I have VS C++ with SP1 and .net 3.5. I am seriously lost because i have no confidence in VS anymore. I have never experienced such random behaviour like this with a program. I feel like i am beta testing a program. Four different projects( out a total of 11 to do experiments and to find out what i do wrong) i started with the last 3 following the desired compliance by VS. They all generate the same error but for different reasons. As soon as i started doing something to the resource file or Turning unicode off, The issues appeared and i could not resolved it. I have also noticed that project settings are not immediately applied even while pressing apply and ok. Doing clean builds also did not help. Turning of precompiled headers also did not help. I tried it systematically changing settings as i did before and adding code to the resource file and i am lost. I do not know why. Also in the resource header created when i start a new project there are two ID constants with the same number 103. Why are these numbers the same ? Are they not supposed to be unique ? I mean this is a template

Code:
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by uitzoek werk.rc
//

[B]#define IDS_APP_TITLE			103[/B]

#define IDR_MAINFRAME			128
#define IDD_UITZOEKWERK_DIALOG	102
[B]#define IDD_ABOUTBOX			103[/B]
#define IDM_ABOUT				104
#define IDM_EXIT				105
#define IDI_UITZOEKWERK			107
#define IDI_SMALL				108
#define IDC_UITZOEKWERK			109
#define IDC_MYICON				2
#ifndef IDC_STATIC
#define IDC_STATIC				-1
#endif
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NO_MFC					130
#define _APS_NEXT_RESOURCE_VALUE	129
#define _APS_NEXT_COMMAND_VALUE		32771
#define _APS_NEXT_CONTROL_VALUE		1000
#define _APS_NEXT_SYMED_VALUE		110
#endif
#endif

From what i have read on the internet, the linker is messing up. I do have noticed that when i press clean build and right after that select the build menu again, there is a whole different menu coming up. Then it changes back to the normal build menu. I am clueless. I have read that several people experienced hanging issues where VS studio seemed to freeze for a while and then started functioning again. I seem to get different menu's and the settings i change are not always updated when i want to build my project or settings are just forgotten.

I think i will just go on and try to get windows xp sp3 compliance while using the borland builder. Maybe the VS C++ 2008 version i have is corrupted or something. Completely unreliable.
 
Last edited:
May 11, 2008
22,175
1,402
126
I forgot to add i also checked the linker settings :
All the settings are the same for a working project and projects where i get the weird error.

These settings are the same and can cause the error according to what i read on the internet I have tried to change those settings to see if it would solve my problems :

Here are all my settings i changed Including the compiler and general setting.



C/C++
Precompiled header > Create prcompiled headers : Yes.
I changed it to No to make sure there was not anything going wrong here.
But this also does not solved it. When starting a new project i turn it off before i compile the first time. This also does not solve the linker errors i continue to get.


Linker :
System > Subsystem : Windows (/Subsystemwindows) If set to console this generates the error. I checked if it was on the wrong setting, it was not.

Advanced > entrypoint : blank. I typed in :WinMain , t_WinMain , Main. Left it blank again. No solution. Same error.

Input > Additional dependencies : Here the libraries that are used must be added. I use commoncontrols but i would get errors when using Initcommoncontrols() and any commoncontrol if i do not add comctl32.lib here. Since this seems to be a separate library I needed to add it manually to this setting. Any external library must be known and i type it here.


General
Character set > Use unicode character set.
This option i changed to not set and use multi bytes character set. When changing this setting to not set or multi byte character i would get the error for example "MessageboxW" is found and the pointer to the string is wrong. I then turn back the switch to unicode , do a clean build and a build and i get the linker error. But not immediately , sometimes i have to do it several times and after editting the resource *.rc file. The messageboxW or messageboxA functions are the same functions, only mssageboxW is for 2 byte unicode and messageboxA is the 1 byte ascii version.


When changing 1 of these settings 1 at a time, i do a clean build and then a build. That is when the error can seemingly random appear. Because it does not happen at once. Sometimes it takes a few times. These are the only settings i changed. I compared the settings between a functional and a non functional project. There are no differences.
 
Last edited:
May 11, 2008
22,175
1,402
126
Well, i have found another issue, i had this before but i thought first that i did something wrong. when i wanted to create a new project, VS just stopped and i received the message project creation failed. This also seems to be a common problem, at least i found that out after googling for it.

However, i again tried a new project with my current VS installation to find the error. But this time i used a different approach. I started a new project(the first time this failed with above error) The second time succes. It is afcourse a windows application. What i did was before i let anything compile i set the following options :

In the targetver header i changed the target windows from windows vista to windows NT 0x500.

Linker
Input > Additional dependencies : i added the comctl32.lib

General
Character set > not set.
I do not use unicode because i have a few plain ascii files to read and i do not want to mess with asii / unicode conversion.

C/C++
Precompiled header > Create precompiled headers : No.

This means that every time everything is compiled. Since my project is not so big, i do not mind waiting a few seconds...

I left the lean and mean windows define alone in the stdafx.h, i will just update all my code that used old windows functions to use new windows win32 api functions.

I decided to wait before editting the *.rc resource file. I left it alone.
I then added the same code from my failed project(described in the posting above) at small pieces at a time and as i expected, there are no errors in the code when doing builds. I did a clean build every time to make sure. I editted the resource header (resource.h) file. All the problems i had before, are up till now non existent. I have not had messageboxW errors even after changing unicode to not set. I even provoked it by setting the unicode option back to use unicode characters. I then let VS build and afcourse the messageboxW errors and other string errors. I then changed it back to not set and the error was gone. I have now editted the resource file and still no error. While using the same support files and same code. I will continue to see where VS will have a problem. Perhaps because i changed all the settings first before actually starting to program,Vs did not get messed up. Up till now , with the same files and code, i do not have seen any errors besides the errors i made myself( sometimes deliberately to invoke a response and to check) But up till now, it works like i am used to from compilers. Like a charm that is...
If i find out what went wrong i will post it. I assume for the moment VS does not like it when i change to much settings at once while their is already a large amount of code.

For now :
If i do get an error i might be able to trace it, if not then i am sure i have a corrupt version ( i got it from a visual studio express cd ). Maybe when i download it , my problems will be solved, that is the problems i do not have at the moment.
 
Last edited:
May 11, 2008
22,175
1,402
126
I am doing a from the ground up coding of my program using VS to find out what is going wrong.

When i entered some buttons i wanted to make,
I received the following warning from VS:

Linking...
LINK : E: \My docs\Visual Studio 2008\Projects\unicodetest\Debug\unicodetest.exe not found or not built by the last incremental link; performing full link
Embedding manifest...


It turns out that my hInstance is not initialized to 0.
When i type this : HINSTANCE hInstance; >> The warning.
When i type this : HINSTANCE hInstance = 0; >> No warnings.
This fixed the warning.
Luckily the debugger popped up with a message that hInstance was not initialized or i would not have known this.


The following bold text is what i suspect went wrong while not setting the unicode option to disable immediately at the start of the project.
This is for a pure ascii program.
Code:
     hWndButton = CreateWindowEx  (NULL,
                                                            [B]"button"[/B],
                                        [B]"Create configuration files"[/B],
                                        WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                        i_cxChar * 30,
                                        i_cyChar * 41,
                                        75 * i_cxChar,
                                        12 * i_cyChar / 4,
                                        hWnd,
                                        (HMENU) i,            // CHILD window ID 1.
                                        hInstance,
                                        NULL);

This bold text is what is expected when you use unicode :

Code:
        hWndButton = CreateWindowEx (NULL,
				       [B]TEXT("button")[/B],
                                        [B]TEXT("Create configuration files")[/B],
                                        WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                        i_cxChar * 30,
                                        i_cyChar * 41,
                                        75 * i_cxChar,
                                        12 * i_cyChar / 4,
                                        hWnd,
                                        (HMENU) i,            // CHILD window ID 1.
                                        hInstance,
                                        NULL);

When i assumed unicode was standard off, which was the default according to my books, multiple of these TEXT() macro errors is what caused mayor errors in VS. But i did not get specific information about this. I would get linker errors. Just like the one above about the hInstance is not that obvious. Even after setting unicode to not set would no longer remove the error. VS was lost too i guess. Now since i started from the beginning with unicode not set i do not have any errors up till now.

When i use strcpy and other functions i used to get the following warning.

e: \my docs\visual studio 2008\projects\unicodetest\unicodetest\drawfunctions.cpp(547) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c: \program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'

To remove this waring i typed the following defines on the top of the *.cpp where the errors are generated. Since i do a lot of parsing and stringsize checking myself, i do not feel the need to use the "save" versions. Redundancy is a fine concept but one can go to far...

#define _CRT_SECURE_NO_DEPRECATE

This i read as tip on daniweb. I have it commented out for now.
//#define _CRT_NONSTDC_NO_DEPRECATE

For anyone that might be interested :

http://www.daniweb.com/forums/thread137036.html
http://msdn.microsoft.com/en-us/library/ms235384.aspx
http://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx

I am used to the following way to make sure a headerfile is not called multiple times by the compiler.
The include guard :

Code:
#ifdef ___MAFIGEN_DRAWFUNCTIONS
	#endif


#ifndef ___MAFIGEN_DRAWFUNCTIONS
	#define ___MAFIGEN_DRAWFUNCTIONS

// Include files
...
..

// Declare Prototypes !
...
...

#endif

To make sure this is not causing confusion to VS i decided to use the
#pragma once statement.
Code:
#pragma once


At the moment i have 0 warnings and 0 errors. :)
The problem is that the error messages of VS are really not always that clear and rather confusing. If i make a mistake or i forget something VS specific, i want to be notified what i do wrong and not with a obscure error message that is used for multiple different situations.

I write this all down, because i am sure i will not be the first or the last who has encountered these kinds of issues.
 
Last edited:
May 11, 2008
22,175
1,402
126
Well, i decided to not use the #pragma once directive.
I will stick with the include guard.

I had some issues with multiple declarations because i used #pragma once in my header files.
Now it is fine. 0 errors and 0 warnings. and 1 succesfull build all the time :D

I only use the pragma once directive in the targetver.h
For now i have removed the directive also from stdafx.h and exchanged it with an include guard.
If i have later on any issues, i can always remove the include guard again and use the #pragma once. But i cannot see why it should not work with the include guard. Up till now everything goes well again.


http://en.wikipedia.org/wiki/Pragma_once

http://en.wikipedia.org/wiki/Include_guard
 
May 11, 2008
22,175
1,402
126
Thank you very much Cogman for your advice ! :D

I ported my code completely to visual studio now from Borland. The same code without modifications now works under windows xp + SP3 when compiled under visual studio. The Borland 5.5 C++ builder works great, but the code it generates does not seem to function properly under windows xp +SP3. Which with hindsight can be expected since it is an old compiler and windows xp + SP3 has some new tricks.

I made my own printf version debug window from a modeless dialogbox together with a listbox control. All i do is send an HWND handle of the dialogbox and a pointer to a 0-terminated string and a small function does some parsing and there after sends the string to the listbox in the dialogbox.

http://i1006.photobucket.com/albums/af186/William_Gaatjes/screenshot3.jpg

I also found the way to work with resource *.rc files.
While pressing on the *.rc file i would get this message :

http://i1006.photobucket.com/albums/af186/William_Gaatjes/screenshot2.jpg

But after some testing, i found out there is an easy way. Just press right mouse button and click "view code" . :awe:
Editing is now fully possible.

http://i1006.photobucket.com/albums/af186/William_Gaatjes/screenshot1.jpg

Also , my common file open, file save functions work now while before under borland i had not yet solved how to tackle that problem. But now i do not have to anymore. It works flawlessly....

Now i can finally continue where i left off, and that is finishing the alpha version of my program and finishing the linker script generator and the makefile generator. After i have it working i can add functions specifically tailored to the arm architecture. Making it a more advanced script generator.
But all in good time ... ^_^
 
Last edited:

Cogman

Lifer
Sep 19, 2000
10,284
138
106
Well good to hear. You should enjoy the VS and all the features it provides. It is hands down the best IDE that I've worked with.