Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing information from EXE in DLL 2

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
0
0
CA
Hello,

I hope I can explain this properly.

I have a project containing a standard exe and several ActiveX Dll projects.

The exe project references the DLL's through a class module and is a part of the exe's references.

How do I do the reverse this process? I want to be in a DLL and access a function from the exe?

Here is an example.
In the exe, I click a menu item, which calls the class DLL to access a particular form in the DLL's project. This form reads, validates and processes certain information. Once the process is complete, the control is returned to the exe. However; during the validation process, I need a particular set of functions located in the exe.

In this case, copy and paste is not an option as the required functions call other series of functions to complete its task.

I hope this is clear and that someone can assist me.

Thanks.
 
I suggest that you include a class module in your parent EXE project.

1. During startup, parent EXE project will create an instance of its own class.
2. After that the EXE will instantiate objects from one or more ActiveX DLLs.
3. Each DLL's class module will expose a public object variable. Using this variable, the EXE will pass a reference of its own object created in step 1, to each DLL.
4. The DLLs will use this object reference to call any member method of the class module belonging to the EXE.
5. The methods in EXE class module will in turn call any function in the EXE scope and return the result to the caller DLL.

This all sounds too complicated, better see an example explaining each step.

1. Start VB with a Standard EXE.
2. Add a class module to the project and change its name from Class1 to clsEXE.
3. Add a standard module to the project.
4. Now add an ActiveX DLL project from the File menu.
5. Change the name of this project from Project2 to DLL.
6. Change the name of its class module from Class1 to clsDLL.
7. Go to Project1 (EXE) refernces and add refernce to DLL project.
8. Insert the following code in modules.
___
[tt]
'Project1.Form1
Private Sub Form_Load()
Dim objEXE As New clsEXE, objDLL As New clsDLL
Set objDLL.objEXE = objEXE
MsgBox objDLL.DllFunction(5)
Unload Me
End Sub

'Project1.clsEXE
Public Function ExeFunction(Argument As Double) As Double
ExeFunction = Square(Argument)
End Function

'Project1.Module1
Function Square(Argument As Double) As Double
Square = Argument * Argument
End Function

'DLL.clsDLL
Public objExe As Object

Public Function DllFunction(Argument As Double) As Double
DllFunction = objExe.ExeFunction(Argument)
End Function[/tt]
___

9. Now step through the program and it will explain how the DLL will be able to use the "Square" function, present in the EXE project.
 
Hello Hypetia,

Thank you very much for your response. I'm glad you understood what I was asking.

I also very much appreciate that you provided code to aid in the example. It made things so much easier to follow.

This is almost exactly what I am trying to accomplish.
I will try it out in my project.

Thanks.
 
Just to let you know I got it working with the help from your code.

Thank you again for the response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top