trimtrom
asked on
Callbacks from a DLL to its calling form
Hello,
I have just started writing ActiveX DLLs, and I have the following question:-
I start my project off by showing Form1. Then it calls an ActiveX DLL called DLL1. Then I want the DLL to be able to access the contents of a textbox in Form1.
Is this what they call a "callback" problem? When I attempt to refer to the textbox in Form1 from the DLL, I get an error message saying that it does not recognise the object (Form1) being referred to.
Must I pass Form1 as an argument when I call the procedure inside the DLL? I am not sure how to phrase this. I would be very grateful for a code example.
Thanks,
Trimtrom
I have just started writing ActiveX DLLs, and I have the following question:-
I start my project off by showing Form1. Then it calls an ActiveX DLL called DLL1. Then I want the DLL to be able to access the contents of a textbox in Form1.
Is this what they call a "callback" problem? When I attempt to refer to the textbox in Form1 from the DLL, I get an error message saying that it does not recognise the object (Form1) being referred to.
Must I pass Form1 as an argument when I call the procedure inside the DLL? I am not sure how to phrase this. I would be very grateful for a code example.
Thanks,
Trimtrom
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Alamo has the closer answer to what I was really intending. I will try passing the text control to the DLL for it to access.
Many thanks for both answers.
TrimTrom
Many thanks for both answers.
TrimTrom
Please explain trimtron, if you liked my answer, why did you accept tomook's answer as correct?
Hmm. I sure got the points, but if you liked alamo's answer you should have rejected mine. How do we fix this?
ASKER
Well,
basically your answer involved subclassing and the API, which I want to understand. So I thought I would accept your advice to invest in the next version of VB, and also the Hardcore VB book.
Where you are coming from, I want to go. So you got the points!
Trimtrom
basically your answer involved subclassing and the API, which I want to understand. So I thought I would accept your advice to invest in the next version of VB, and also the Hardcore VB book.
Where you are coming from, I want to go. So you got the points!
Trimtrom
OK, works for me. Thanks.
First of all, no, this is not what is normally called a "callback". A callback is when you call an external API function and give it the address of a sub or function in your program to "call back" . One example of this is the windows API "EnumWindows" function to enumerate windows: you call it with the address of one of your functions, it then calls that function once for every window in the system. ActiveX DLLs written in VB can not call callbacks.
Next, you are correct that you can't pass a form to an ActiveX DLL in VB5, but you *can* pass a control such as the textbox itself. The ActiveX DLL can then access and change the contents of the text control. As an example, in the called ActiveX DLL you could declare the following member of Class1:
Public Function GetSetText(ctrl As Variant) As String
GetSetText = ctrl.Text
ctrl.Text = "the text changed!"
End Function
You could then call it from your VB program as:
Dim testObj As Class1
Set testObj = New TestDLL.Class1
t$ = testObj.GetSetText(Form1.T
I hope this helps, good luck!