Advertisement

C++ & ATL

Started by June 24, 2000 04:45 PM
10 comments, last by Shannon Barber 24 years, 5 months ago
I was curious if anyone has experience working with microsoft''s ATL. They claim it has little overhead, but I''m spectical at best... I was looking at the CWindow and like classes, not the ActiveX ones...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Skeptical when compared to?

They are great for building lightweight controls as opposed to full blown MFC apps and hand coding COM objects from scratch, but again, it depends on what you ultimately after...


YAP YFIO,
deadlinegrunt

~deadlinegrunt

Advertisement
Hehe, I don''t think anything could be more bloated than MFC - but I''m sure MS will surprise me yet.

CWindow as opposed to just making the API calls yourself - the message mapping macros seem cumbersome...


More importantly, how do you create a CWindow? The sdk sayes include atlwin.h, compile that, error sayses to include atlbase.h
compile that, ok, link that hundreds of bad links... wtf - oh eheh I probably need a .lib don''t I
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
atl.lib, go figure
oh well, I already wrote my own encapsulation class...
I read a question on the board somewhere about doing this, putting winproc in a class etc... If you read this, post & i''ll send ya the code.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Yes, you will need the atl.lib linked in too

The biggest difference from using MFC compared to ATL as far as windows objects and controls it that you will have to programmaticly do it all on your own. Simliar to BASIC compared to C++. ( That''s not a lighter fluid for a flame war ) It''s not that you can''t do it, it''s just that you have to roll your own code and start from scratch more times than not.



YAP YFIO,
deadlinegrunt

~deadlinegrunt

Hmm, An encapsulation class for a Win32 API wrapper. This is scary. What next, a wrapper for your encapsulation class.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
Advertisement
heheh
yeah yeah... I was curious to see if it could be done and how hard it was... - and no I didn't write an encapsulation class for CWindow - I wrote my own CWindow... an encapsulation of the Win32 API calls...

I want it all to be C++ not a hodge-podge...



Edited by - Magmai Kai Holmlor on June 26, 2000 9:27:57 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Hmmm... I better get out those tutorials on my hard drive about ATL.

- DarkMage139
"Real game developers don't change the rules. Real game developers don't break the rules. Real game developers make the rules!"
"Originality (in games) is the spice of life!"
- DarkMage139
Note that CWindow and CWindowImpl are declared as templates and they are in a header file. Just like STL, there is no .cpp file for them. To use a template, you must instantiate (declare an instance of) the template in your own .cpp file. Then the compiler only compiles the parts of the template that your code uses. (Works just like an inline function, if you never use it, it wont be in the binary image.)

Don't take my word for it though. Try this for yourself.
Go to your project settings, click on the C++ tab. Select "Listing Files" on the "Catagory" pull down, and select "Assembly with source code" from the "Listing file type" pull down. This will put the /FAs compiler switch in the compiler's command line. Now compile and go look at the .asm file that gets generated. Where are the template functions that you never instantiated?

Take this proof a step further and try to do it all with functional orineted code using only Win32 API. Also look at the size (in bytes or in kb) of the resulting .EXE. One of the major differences is that CComModule does some book keeping for you. Overall though, the difference is insignificant. The real benefit is that you have less platform specific source code to keep track of and rewrite.

I don't know what exactly you mean by a wrapper but the MSDN documentation suggests that you inherit from CWindowImpl.
I think this is how I did it.
                                            // S T D A F X . H#define WIN32_LEAN_AND_MEAN#include <atlbase.h>extern CComModule _Module; // Must have this here for CWindowImpl#include <atlwin.h>// W I N M A I N . H#include "StdAfx.h"extern const char _strName[]; struct CRodentiaWindow : public CWindowImpl<CRodentiaWindow>{   DECLARE_WND_CLASS_EX( _strName, CS_HREDRAW/CS_VREDRAW, COLOR_APPWORKSPACE )    BEGIN_MSG_MAP(CRodentiaWindow)              // Note carefully that        MESSAGE_HANDLER( WM_DESTROY, OnDestroy ) // these are not the   END_MSG_MAP()                               // same macros used in MFC   LRESULT OnDestroy(UINT, WPARAM, LPARAM, BOOL&)   {      PostQuitMessage(0);      return 0;   }};// W I N M A I N . C P P#include "WinMain.h"const char _strName[] = "Ferocious Amoebae";CComModule _Module;CRodentiaWindow _Win;INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ){   // There is one and only one instance.   {      HWND hWndPrev;      hWndPrev = FindWindow( NULL, _strName );      if( NULL != hWndPrev ) { SetForegroundWindow( hWndPrev ); return 0; }   }   _Module.Init( NULL, hInst );   {      // Set screen resolution here.      RECT rcScrn;      rcScrn.left = 0;      rcScrn.top = 0;      rcScrn.right = 800;      rcScrn.bottom = 600;      // Create the window with one line of code           _Win.Create( NULL, rcScrn, _strName, WS_OVERLAPPEDWINDOW/WS_VISIBLE );      // This will take the title bar and frame off the window      _Win.ModifyStyle( WS_CAPTION/WS_BORDER/WS_THICKFRAME, WS_EX_TOPMOST, SWP_FRAMECHANGED );      _Win.ShowWindow( SW_SHOW );      _Win.UpdateWindow();   }   // Put directX creation here   {   }   // Put Standard Message Loop here    {   }   // Exit   return 0;}                                            


"Do you bury me when I'm gone?
Do you teach me while I'm here?"
- James Hetfield



Edited by - Marsupial Rodentia on June 26, 2000 12:21:32 PM

Edited by - Marsupial Rodentia on June 26, 2000 12:22:16 PM

Edited by - Marsupial Rodentia on June 26, 2000 12:23:15 PM

Edited by - Marsupial Rodentia on June 26, 2000 12:31:43 PM

Phew! Too many little technicalities. Sometime, I'm going to edit this and get it all correct before someone flames me. Let me know if this is helpful. I wish I could find that one MSDN article about doing this.

Edited by - Marsupial Rodentia on June 26, 2000 12:43:35 PM

Edited by - Marsupial Rodentia on June 26, 2000 12:52:54 PM


Edited by - Marsupial Rodentia on June 27, 2000 12:12:46 PM
Does anyone else on this forum use ATL?

"Do you bury me when I'm gone?
Do you teach me while I'm here?"
- James Hetfield

This topic is closed to new replies.

Advertisement