Win32 API Beginning help

Hello! I am making a Win32 program, and I working on how to make a window... I have all the code to make it work, however, I want to make a function that I can call in order to open the window. It should work, however the problem is when I should call:

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)

I understand that should be the entrance point for any Win32 API program, however, what if I want to create a "main.cpp" to call the function (to make the window) which is in a "window.h"? How would I either be able to call that function, or how would I get the parameters passed to the program when using that function call as the entrance point? All I really need are the parameters, because I need them for creating the window. Thanks for any help!

- Kyle
You probably don't want to hear this... but if you don't understand function parameters (a fundamental cornerstone of C++), I really doubt you are ready to tackle WinAPI.
Oh, no... That is not what I want to hear. I have been programming in C++ for about three years, and I would hope that I understand function parameters... With that said, the windows operating system passes certain parameters to the program when the program uses int WINAPI WinMain as the entrance point.

Just as every C application and C++ application must have a main function as its starting point, every Win32-based application must have a WinMain function.

(one of the many places that is stated)

Sorry if the OP was confusing, but I am not sure how else to explain my problem. Any help is appreciated!
Last edited on
So I must have misunderstood... but I'm still confused. Are you saying you want to call WinMain and don't know how to pass the parameters to it?

You shouldn't be doing that. WinMain is the entry point and isn't a function you'd normally want to call.

Any parameters coming in to WinMain are provided by Windows so you don't have to worry about where they come from.
No, the thing is that I do NOT want to call WinMain, but I still need the parameters that would be passed to it if I had called it at the beginning of the program.
I'm still confused. You have the parameters to it, and it is called at the beginning of the program. It's the entry point.

int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
    // program starts here

    // you can use the 4 parameters here

I'm still not sure I get what you're asking. Can you give me an example or something.
Do you mean how to get command line arguments passed to your program or what ?

You can just ignore the 4 parameters if you don't need it (most programs usually don't need them anyway).
modoran wrote:
(most programs usually don't need them anyway)

You kind of need the HINSTANCE to register and create a new window.
Disch, I don't want WinMain to be the entrance point of the program. I want to have a window class in a separate .h file, that I can include into a main.cpp file, which has a int main() function where the program starts... From there, I want to be able to call; (from my window class) which would open a window. The problem comes in when I need the parameters for the creation of the window. Main just hinstance:

WCE.lpfnWndProc = WndProc;
WCE.cbClsExtra = 0;
WCE.cbWndExtra = 0;
WCE.hInstance = hinstance;
WCE.hIcon = NULL;
WCE.hCursor = NULL;
WCE.lpszMenuName = NULL;
WCE.lpszClassName = WindowClass.c_str();
WCE.hIconSm = NULL;

As you see, I need hinstance in order to make my window class.

So, modoran, all I need IS the arguments that would be passed to the program if I had WinMain as the entrance point.

I am probably just being a fool, and not able to find some sort of function call that would give me the information I need, so that is why I need your help.
Last edited on
HINSTANCE is GetModuleHandle (NULL);

However, what you are trying to do is not recommended and contradicts what you are saying before, that you are not trying to call WinMain directly.

Why the hell do you want that ? You will still get an annoying console windows if you do it.

Why not use a GUI application ? If you really need a console window there is AllocConsole() function.
Last edited on
I'm sorry modoran, I do not understand what you are trying to ask... I am making a small game engine that I can code in my free time, and I figured a good of a spot as any would be to make class for opening, closing, and dealing with windows. That is why I don't want to have to start in WinMain... I want the program to be as flexible as possible. So, I guess I do not want the console window, but I was going to get to that part later, because it was not my main concern as of right now... I wanted to only use C++, Windows, and OpenGL to make it. So, my next question would be if I am going at this the wrong way. Am I? If not, I'll happily just use GetModuleHandle(NULL); in order to get the hinstance I need...
Last edited on
From what you are saying maybe you are trying to write a library or a dinamic link library (*.DLL) ?
These are a collection of functions which can be used by other programs.

Otherwise, if you don't want a console window and want to make a full program use WinMain. THere is no other way around.
Topic archived. No new replies allowed.