Solved

Simple Dynamc Linked Library Loading

Posted on 2002-04-24
6
171 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
[X]
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
  • 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
Independent Software Vendors: 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!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
WinWaitActive parameters 12 31
viewing source code from eclipse 13 111
Line meaning 9 99
c++  placing data into a form and an editbox 5 50
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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