Solved

Simple Dynamc Linked Library Loading

Posted on 2002-04-24
6
163 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 50 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Importing  SSL Certificate into Firefox using GPO 28 193
repeateFront java challenge 31 87
ORA-01403: no data found 43 82
no14 challenge 14 56
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now