Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple Dynamc Linked Library Loading

Posted on 2002-04-24
6
Medium Priority
?
187 Views
Last Modified: 2013-11-20
Hello experts,
i'm just learning how to use MFC dlls. The dlls that i have created have a CWinApp class. I was reading through MSDN, and it said that i should put my init code in the InitInstance function of my MFC dll. It said that this function was invoked by the DllMain function handled by MFC. i just want to get the basics of getting my dll working. I've searched the internet and MSDN and have found no tutorials [i'm sure they're there and if you know of a good like that would be great.]

I want to be able to just load a dll and have it preform some action [just to prove it opened, like showing a messagebox.] Do I need to export my functions with the MFC dll? When does my InitInstance function get called? Where should i put the body code of my dll [in an exported function?]. I would appreciate having this subject which is quite cloudy to me, cleared up.
0
Comment
Question by:cocoabutter46
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
goodami earned 200 total points
ID: 6965252
Hi cocoabutter46,

Yuo can create Dll's in two ways using MFC.You can use the MFC wizard for both the ways.

1.First way is to use MFCAppWizard(Dll)
2.Second is to use ATL ComAppWizard.

The Basic Differnce between these two is the Underlying Techonology ie.COM(a very Powerful one :-)

1a)We Will first Discuss about the First method using MFCAppWizard.This creates a Simple Dll.In this just open the wizard and lets say you type MFCTestDll in Project Name.
1b)Select the Defaul Option of MFC shared Dll in next Pane and click Finish.
1c)the skeleton Project is ready to be used.
1d)You can Simply Give a MessageBox using AfxMessageBox("Hello from MFCDll") in CMFCTestDllApp() Class.
1e)Now you have to test this Dll by loading this Dll.
1f)Open any new project lets say a Dialog based appl. and the Following code to any Button for.eg.

BOOL OnOK()
{
   LoadLibrary("C:\\Temp\\MFCTestDll.dll");
}
 You Will get the above message.

2)NOw we talk about ATL Dll which can ct like a COM Server

2a)In this just open the wizard and lets say you type ATLTestDll in Project Name.
2b)Select the Option of Dll in next Pane and click Finish.
2c)the skeleton Project is ready to be used.
2d)Now Go to "Insert" in menu options and then Select "New ATL Object".
2e)This will give you a new pane to be filled as ATL object Wizard.
2f)Select The default options and click NEXt.
2g)New Object Property Dialog box will appear .Type ComTest in Names box and rest all the Edit Boxes will be filled automatically.
2h)Click OK and you will see that one new Class as CComTest and an Interface as IComTest will be added.
2i)Right Click the IComTest Interface and select AddMethod.
Write Display in Method Name Pane and select OK.
2j)Go to ComTest.cpp and Write a message Box in the Display method.
2k)Select the "Release Min dependency" to build the Dll.

Dll is ready to be used.Yuo can use the same above LoadLibrary to use the Dll otherwise you can type the following VB code :

Private Sub Command1_Click()
Dim x As New ComTest
x.Display
End Sub

after setting the Dll In VB "references" Menu option


**You can Also make your Simple MSC Dll as ATL COM Dll by inserting ATL object.

I hope that I am able to answer all your Queries.

Regards,
Goodami
0
 
LVL 2

Expert Comment

by:manojbkumar
ID: 6965300
hI cocoabutter46
Want Dll Tutorial!!
Look at
http://www.mindcracker.com/mindcracker/c_cafe/dll.asp

contains some good tutorials
0
 

Author Comment

by:cocoabutter46
ID: 6967198
I'm just doing a really simple thing, so normal MFC dlls sound easier than ATL. When i call Load library I get this error:
MYHOSTAPPLICATION caused an invalid page fault in
module THEXTENSION.DLL at 0167:10001323.

Then 2 more that look the same but are in MFC42.DLL. I tested the code and i'm positive that the error occurs on this line.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:goodami
ID: 6967766
Simply Write LoadLibrary("C:\\Temp\\Test.dll")**Hardcoding only to see that this working** in your program and then see.

Cheers,
Goodami
0
 

Expert Comment

by:goodami
ID: 6968021
Simply Write LoadLibrary("C:\\Temp\\Test.dll")**Hardcoding only to see that this working** in your program and then see.

Cheers,
Goodami
0
 

Author Comment

by:cocoabutter46
ID: 6970130
same error
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

885 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