CallBack function question

Just starting out? Need help? Post your questions and find answers here.
ManMartin
New User
New User
Posts: 5
Joined: Sun Jan 27, 2008 12:07 am
Location: Spain

CallBack function question

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
ManMartin
New User
New User
Posts: 5
Joined: Sun Jan 27, 2008 12:07 am
Location: Spain

Post 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.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post 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)
Windows 7 & PureBasic 4.4
ManMartin
New User
New User
Posts: 5
Joined: Sun Jan 27, 2008 12:07 am
Location: Spain

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Post Reply