Question about what to consider when making C++ wrapper classes for Win32

Started by
24 comments, last by _goat 17 years, 10 months ago
you can define:
int APIENTRY XMain();
then inside your class.cpp file
int CALLBACK WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
return XMain();
}
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Advertisement
Quote:Original post by sgalland
I see, so it is not possble to wrap C++ class around the entire Win32 API...

You have no idea of the (ever-expanding) scope of the Win32 API.

"Win32" is not a reference to the graphical window object you see and interact with. It is the name of the 32-bit Windows subsystem, and it includes a ton of functionality that has absolutely nothing to do with graphical user interfaces. It is the successor to Win16, and may one day be completely superseded by Win64 (though Microsoft is hoping that WinFX will largely supersede it instead, with Win64 being used only for low-level components).

You have three problems:
  • You don't know Win32
  • You don't know C++
  • You don't know programming

Based on the above, you are the absolute last person who should be writing a Win32 window class wrapper. I wrote one three or four years ago, which is widely referenced, and it's garbage. Fortunately, it was largely for illustrative purposes.

Just use ATL/WTL. You can hold to the notion that using something you don't understand is a bad idea, but that's why there's documentation. Read it. Plus, ATL's CComPtr lets you use DirectX interfaces in RAII, something you'll probably grow into later.

Basically, it comes down to this: do you want to make cool games, or do you want to re-create technology that's been done and represents zero innovation whatsoever?
I dont even know why I posted here anymore, I didnt post to get my ass treated like dirt because everyone knows more than me. You are right, I am not a professional programmer, I know enough Windows API code for my purposes, I have only programmed in C, VB, and a little in Java. Hell, I can use most aspects of C++ such as using things like vectors and most other legacy functions. If you just want to be a dick fine, I don't care but I don't need you bashing me in a friggin newbies forum. Who the hell are you?
a few things to consider when making a basic win32 wrapper (windows and gdi):
1.) don't wrap anything that doesn't need to be wrapped (Direct3D for example).
2.) don't implement dispatch tables (takes too long) or 1,000 virtual functions (inefficent use of memory, since most derived classes only override 10-20 windows messages) for your windows message routing. just use a single virtual Window/Dialog/SuperClass/SubClass proc. maybe add a virtual WM_COMMAND handler as well.
3.) when wrapping GDI classes, be careful! gdi objects can be selected into multiple contexts, and when you destroy a gdi object that is currently selected into a DC or DCs, what do you do? throw an exception? restore the original object? select a default object? this requires a fair amount of bookeeping (reference counting, a map of objects and dcs they are selected into).
4.) superclass the windows common controls.

other than that, making a basic win32 wrapper isn't too hard and shouldn't take so much time. just don't go all balls out and reinvent MFC.
I just wanted to post and state that I am sorry for my anger issues. You are all trying to help me and I get mad when I should realize my iniquities. So I formally ask for your apologies. I intend to let this thread die however, all my questions been answered. I spend my time being nice to everyone since I am in customer support for a major firm who builds servers/does 3rd part Microsoft application support and when it comes to getting any support or attempting to get answers from a community with a wide variety of opinions and idea's I find it frustrating when I work in a highspeed high anxiety enviroment, and I don't need to bring my frustrations on here and dump, its not right. Sorry.
Quote:Original post by sgalland
I just wanted to post and state that I am sorry for my anger issues. You are all trying to help me and I get mad when I should realize my iniquities. So I formally ask for your apologies. I intend to let this thread die however, all my questions been answered. I spend my time being nice to everyone since I am in customer support for a major firm who builds servers/does 3rd part Microsoft application support and when it comes to getting any support or attempting to get answers from a community with a wide variety of opinions and idea's I find it frustrating when I work in a highspeed high anxiety enviroment, and I don't need to bring my frustrations on here and dump, its not right. Sorry.


A simple apology will do.

Listen to Oluyesi - he can sniff incompetence out ten-thousand miles away. This doesn't mean that you're a bad coder, it just means you're incompetent. Everybody is when they start out. Don't take it personally.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]

This topic is closed to new replies.

Advertisement