Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2001-09-08
12
459 Views
Last Modified: 2013-11-20
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
Comment
Question by:Surfer
  • 8
  • 3
12 Comments
 
LVL 1

Expert Comment

by:MRNMurthy
ID: 6468016
Hi,

I will try to send the code.

From

MRN Murthy
0
 

Author Comment

by:Surfer
ID: 6468770
That would be great!  I look forward to your email.
0
 

Author Comment

by:Surfer
ID: 6469022
That would be great!  I look forward to your email.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Surfer
ID: 6469144
That would be great!  I look forward to your email.
0
 
LVL 3

Expert Comment

by:cypherljk
ID: 6471835
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
 

Author Comment

by:Surfer
ID: 6473242
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
 
LVL 3

Expert Comment

by:cypherljk
ID: 6475157
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
 

Author Comment

by:Surfer
ID: 6475178
How do I use explicit linking to call this class from my exe?
0
 

Author Comment

by:Surfer
ID: 6475189
How do I use explicit linking to call this class from my exe?
0
 

Author Comment

by:Surfer
ID: 6475190
How do I use explicit linking to call this class from my exe?
0
 

Author Comment

by:Surfer
ID: 6475191
How do I use explicit linking to call this class from my exe?
0
 
LVL 3

Accepted Solution

by:
cypherljk earned 200 total points
ID: 6475226
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 66
while loop over for loop 7 115
ffmpeg - "rtsp://...... Operation not permitted" 4 86
modThree challenge 4 96
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question