Re: breaking changes from ATL 7.0 to 7.1 ? Problem with GetMessage()

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Andrew Walker (bibsoconner_at_yahoo.com)
Date: 07/08/04


Date: 8 Jul 2004 09:31:13 -0700

Thanks Igor and Alexandar! That makes sense. Can I now ask about the
second thing that seemed different between 7.0 and 7.1. If I add a
few lines of code to the FinalConstruct Function:

HRESULT FinalConstruct()
{
  BOOL rc = FreeConsole();
  rc = AllocConsole();
  SetConsoleTitle("TestConsole for AtlObject: Info");

  fclose( stdout );
  freopen( "CON", "a", stdout );
  printf("STDOUT redirected\n");

  pDlg = new CAtlDlg(); // new line - CAtlDlg isa public
CAxDialogImpl<CAtlDlg>
  pDlg->Create(NULL, NULL); // new line
  pDlg->ShowWindow(SW_SHOWNORMAL); // new line
  return S_OK;
}

again I get the results with 7.0 that merely hitting "debug" or run
will result in the console window coming up, AND the very simple
dialog. With 7.1 nothing happens until you launch a client app (for
reasons Igor explained). My client app is a simple C# app where I
write the following code:
private void Form1_Load(object sender, System.EventArgs e)
{
        ATLDlg4Lib.IAtlObject Obj = new AtlObjectClass();
}

The funny thing is that the console window comes up, and the simple
dialog comes up - sort of. It comes up, but it's not complete. The
only button I put on the dialog (a dummy button that does nothing for
this example) is missing. It's as if the dialog never got painted all
the way. The frame is there, as is the title on the title bar, and
the close button (the 'X' at top right). Again, this all works fine
with 7.0 - you can either launch the ATL executable and then the
client, or let the client launch the ATL executable. Either way, the
dialog comes up fine.

My questions are:
1. Is this dialog behavior also related to the Singleton Class
Factory implementation change from 7.0 to 7.1? Or is there something
else I am doing wrong that 7.0 allowed me to get away with?
2. Is there a way to fix it? And is there a way to have the
singleton class factory create its objects during initialization as in
7.0 and 7.1?
3. Looking ahead, Alexandar gave me some warnings about using
IsDialogMessage and modifying the WinMain function. My (Wizard
Generated) WinMain function looks like:
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE
/*hPrevInstance*/,
                                LPTSTR /*lpCmdLine*/, int nShowCmd)
{
    return _AtlModule.WinMain(nShowCmd);
}

I.e. it simply calls _AtlModule.WinMain. What's the standard way for
incorporating other behavior, such as IsDialogMessage. Presumably I
still need to call _AtlModule.WinMain? As I recall, in Visual Studio
6.0, the WinMain was at the top level and easy to modify.

Thanks again for all the help. I do appreciate it.
-Andrew

"Igor Tandetnik" <itandetnik@mvps.org> wrote in message news:<emi9j7GZEHA.4008@TK2MSFTNGP09.phx.gbl>...
> "Andrew Walker" <bibsoconner@yahoo.com> wrote in message
> news:ac96aac3.0407071306.19f7d674@posting.google.com
> > I did this mostly to verify that I was going into FinalConstruct. I
> > also modified one line in stdafx.h ...
> > #define _ATL_FREE_THREADED // my code
> > //#define _ATL_APARTMENT_THREADED // original code
> > Finally, I added the following macro:
> > DECLARE_CLASSFACTORY_SINGLETON(CAtlObject)
> >
> > When I hit debug, I go into FinalConstruct and a console window is
> > brought up.
> > However, when I close down Visual Studio 7.0, bring up 7.1 and rebuild
> > the project, I never go into FinalConstruct!
>
> In VC6 and VC7, singleton class factory creates its global object during
> initialization (the object is actually a data member of the class
> factory). In VC7.1, singleton class factory creates the object lazily,
> only when the first client requests it, then keeps it around until the
> server is terminated.



Relevant Pages

  • Re: breaking changes from ATL 7.0 to 7.1 ? Problem with GetMessage()
    ... ATL could get a few pointers from this design... ... > few lines of code to the FinalConstruct Function: ... With 7.1 nothing happens until you launch a client app (for ... In VC7.1, singleton class factory creates the object lazily, ...
    (microsoft.public.vc.atl)
  • Re: Anything like this for Delphi?
    ... Create a new unit with a singleton class, ... Use this unit from the main form's and the client forms' units. ... In main form's constructor, assign the JvDockStyle to the ...
    (borland.public.delphi.thirdpartytools.general)
  • Dont know whats going wrong!
    ... I've just started exploring .NET remoting, and i'm having a queer ... my Singleton class isn't a Singleton! ... I have used config files to set up the servr and client. ... i instantiate the remote object at the client as follows: ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: COM activation models
    ... > COM object which dutifully caused the object's FinalConstruct to be ... Only with singleton class factory. ... The outcome was that CoRegisterClassObject in VS2003 only ... > registered the class factory of the object. ...
    (microsoft.public.vc.atl)
  • Re: breaking changes from ATL 7.0 to 7.1 ? Problem with GetMessage()
    ... "Andrew Walker" wrote in message ... > I did this mostly to verify that I was going into FinalConstruct. ... singleton class factory creates its global object during ...
    (microsoft.public.vc.atl)