COM object problem

I have written a COM object using the
visual c++ wizard (DLL with automation).
The COM object has the standard DllRegisterServer, DllGetClassObject,
QueryInterface, etc ... I have also
implemented a class factory within the
COM object. My actual object is a CCmdTarget based class which has a handful of methods (including QueryInterface, AddRef, etc..) exposed.
now the problem. I am able to register the COM object, I can create a class factory object and then create my CCmdTarget based object. within the CCmdTarget object one of the methods allows me to create and display a modeless dialog. the method to create the dialog is accessed when a toolbar button on the main application window is pressed. I am able to create and display the dialog correct. within the application main window I also have a routine that uses the CCmdUI to control the state of the toolbar button ,keeping it in the pressed state as long as the modeless dialog box is displayed. I check the state of the dialog box by calling a method within my CCmdTarget class that that uses IsWindowVisible() to check if the dialog is visible. for some reason when I call this method my pointer and HWND
handle are invalid for the dialog box I created earlier and I get a memory error,  what is going on ????
C_HAGAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
Make sure Ur passing the exact pointer U get while UR creating it.
0
shaigCommented:
Is the dialog local to the function where the DoModal function is called?
If yes, the dialog object is on stack and no referencing should be allowed after the functon exits.
You should hold the dialog object as a data member.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.