awd
asked on
AfxGetApp() Source Code?
I need to know where the source code for AfxGetApp() is located. I am trying to derive my own class from CWinApp and am calling this function from an MFC extension DLL. The problem is that I am not able to use this function to call the functions I overrode in my derived class.
Thanks.
AWD
Thanks.
AWD
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
look at the help files on AFX_MANAGE_STATE. the module state information includes a ptr to the app.
ASKER
Is the AFX_MANAGE_STATE macro necessary if the DLL is an MFC extension DLL? I thought this was only used with regular DLLs.
on second thought, no it's not, but you should be able to do the same thing in the extension dll as in your app. I looked at some production code we have at work that does precisely what your doing. it's an extension dll, and it casts the result of AfxGetApp. I suggest you try it.
ASKER
I would like to try it. I have 2 problems:
1. If I try to cast the AfxGetApp() call in the DLL, I can't get it to recognize the class I need to cast to (the one that I derive from CWinApp).
2.A call to AfxGetApp() works in the main program returning a reference to the object instantiated from my class. I don't need to cast it here anyway. I don't even need to call AfxGetApp() here.
Am I just missing something obvious?
I do appreciate your time. I am new to Experts Exchange. Is 50 pts a reasonable amount for this question?
1. If I try to cast the AfxGetApp() call in the DLL, I can't get it to recognize the class I need to cast to (the one that I derive from CWinApp).
2.A call to AfxGetApp() works in the main program returning a reference to the object instantiated from my class. I don't need to cast it here anyway. I don't even need to call AfxGetApp() here.
Am I just missing something obvious?
I do appreciate your time. I am new to Experts Exchange. Is 50 pts a reasonable amount for this question?
pts aren't that relevent to me, and I'm pretty new. you do need to include the class declaration for your app in the module in the dll that's calling it.
e.g.:
yourApp.h:
class myApp: public CWinApp
{...};
yourExtensionDll.cpp:
#include <yourApp.h>
.
(myApp*)(AfxGetApp())->you rFunctionH ere();
understand?
e.g.:
yourApp.h:
class myApp: public CWinApp
{...};
yourExtensionDll.cpp:
#include <yourApp.h>
.
(myApp*)(AfxGetApp())->you
understand?
ASKER
I understand your suggestion. I keep getting
'CmyApp' : undeclared identifier
I just went through my code. I have the myApp.h included in the CPP file for the object in my DLL file that makes the function call. And I am casting it the same as your suggestion.
I have went so far as to put a full path between quotes in the #include directive. I'm stumped! Any thoughts? Could anything other than the header file be the problem?
'CmyApp' : undeclared identifier
I just went through my code. I have the myApp.h included in the CPP file for the object in my DLL file that makes the function call. And I am casting it the same as your suggestion.
I have went so far as to put a full path between quotes in the #include directive. I'm stumped! Any thoughts? Could anything other than the header file be the problem?
I'm out of suggestions. sorry.
ASKER
Thanks for the help. You more than answered the original question.
ASKER
How can I reference the class I need to cast to (it resides in the main program)? The cast needs to be done in the DLL.
Thanks.
-Albert