[Webinar] Streamline your web hosting managementRegister Today

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

Simple Dynamc Linked Library Loading

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
cocoabutter46
Asked:
cocoabutter46
  • 3
  • 2
1 Solution
 
goodamiCommented:
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
 
manojbkumarCommented:
hI cocoabutter46
Want Dll Tutorial!!
Look at
http://www.mindcracker.com/mindcracker/c_cafe/dll.asp

contains some good tutorials
0
 
cocoabutter46Author Commented:
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

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

Cheers,
Goodami
0
 
goodamiCommented:
Simply Write LoadLibrary("C:\\Temp\\Test.dll")**Hardcoding only to see that this working** in your program and then see.

Cheers,
Goodami
0
 
cocoabutter46Author Commented:
same error
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

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