Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

explicitly load a MFC extension DLL that exports a CObject derived class?

Is it possible to explicitly load a MFC extension DLL that exports a CObject derived class?  The calling exe is an MFC app.  I have no problem doing this using a .lib file linking implicitly.  Can you please supply a small code sample.  
0
Surfer
Asked:
Surfer
  • 8
  • 3
1 Solution
 
MRNMurthyCommented:
Hi,

I will try to send the code.

From

MRN Murthy
0
 
SurferAuthor Commented:
That would be great!  I look forward to your email.
0
 
SurferAuthor Commented:
That would be great!  I look forward to your email.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
SurferAuthor Commented:
That would be great!  I look forward to your email.
0
 
cypherljkCommented:
Surfer,

What is that you can not do? Do you need to know how to load a dl explicitly or do you need to know how to export a MFC derived class in a dll?  If you explain a bit more we can help you.

My 2 cents...
0
 
SurferAuthor Commented:
The main part of my question is:

I have a class
AClass : poblic CObject
{
...
}
I want to export my class from my DLL to the calling app.  If I use implicit linking I know what to do.  However, if I link explicit, what is the best way to import this class into my exe?  I know who to use exlictt linking with functions, but how do I do it with a classes and is it safe?

Thanks
0
 
cypherljkCommented:
Surfer,

To export an entire class from a dll you must prefix the class with AFX_EXT_CLASS like so...
class AFX_EXT_CLASS AClass : public CObject
{
...
}


and of course your dll must be an MFC extension dll since you are subclassing CObject

My 2 cents...
0
 
SurferAuthor Commented:
How do I use explicit linking to call this class from my exe?
0
 
SurferAuthor Commented:
How do I use explicit linking to call this class from my exe?
0
 
SurferAuthor Commented:
How do I use explicit linking to call this class from my exe?
0
 
SurferAuthor Commented:
How do I use explicit linking to call this class from my exe?
0
 
cypherljkCommented:
1.) Create an AFX_EXTENSION_MODULE object in your application i.e. the CWinApp derived object
ex.

static AFX_EXTENSION_MODULE extMyExtesnion;

2.) Call AfxLoadLibrary() passing in the name of your library

3.) Call the API function AfxInitExtensionModule() in your application's InitInstance() function passing it the address of your object in step 1 and and handle returned from step 2

4.) Add the following to your dll code in the dllmain
if (uReason == DLL_PROCESS_ATTACH)
{
    if (!AfxInitExtensionModule(extMyExtension, hInst)
        return;
    else if (uReason == DLL_PROCESS_DETACH)
        AfxTermeExtensionModule(extMyExtension);
}

5.) Call AfxFreeLibrary() passing in the handle to the library when you app exits

This will allow you to create a manages instance of the exported class object like a view etc etc.

My 2 cents...
       
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now