Page 1 of 1

CallBack function question

Posted: Sat Apr 19, 2008 8:30 am
by ManMartin
Hello:

I am new in PureBasic.

I have some programs in VisualBasic and I would like to create a dll in Purebasic and pass the "AddressOf" of a procedure of VisualBasic (like some api functions in WinOS).

My question is how I can call the function of VisualBasic from PureBasic Dll once I have the address number of the procedure.

Is there a way to call this procedure by a simple "long" number recieved by the PureBasic Dll?

My final goal is not to use PureBasic as simple Wrapper dll but gain some power to my app dividing the tasks into threads managed by Purebasic Dlls.

Thanks to all.

Posted: Sat Apr 19, 2008 9:36 am
by Trond
Something like this:

Code: Select all

Prototype.l ProtoMyFunctionType(Parameter.l)

Global MyVariable.ProtoMyFunctionType

MyVariable = GetAddressOfFunction() ; Associate MyVariable with the function address
MyVariable(12345) ; Call function address

Posted: Sat Apr 19, 2008 1:20 pm
by ManMartin
Thanks a lot for the quick response.

I dont get the idea but I will make a test to discover the secrets.

cheers.

Posted: Sat Apr 19, 2008 1:45 pm
by milan1612
Trond uses Prototypes, which is a technique of PureBasic that has various advantages over the following, much more simple method:

Code: Select all

address.l = SomeFunctionThatReturnsAFunctionAddress()
CallFunctionFast(address)

Posted: Sat Apr 19, 2008 2:01 pm
by ManMartin
This method seems more easy to understand to me...

I will take a look in the help to try to understand Prototypes too.

Thanks to all.

Posted: Sat Apr 19, 2008 2:37 pm
by srod
With Visual Basic functions in particular, you may find that you have to pass strings in OLE format (BSTR). For these, prototypes are ideal when combined with pseudotypes etc.