Call host program procedure from DLL?

Just starting out? Need help? Post your questions and find answers here.
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Call host program procedure from DLL?

Post by wombats »

Hi,

Is it possible to call a procedure in the host/main program from a DLL, both of which were programmed in PB?

Thanks.
User avatar
Demivec
Addict
Addict
Posts: 4090
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Call host program procedure from DLL?

Post by Demivec »

Use a passed pointer reference and a prototype.
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: Call host program procedure from DLL?

Post by wombats »

I don't really know how to do that. What am I doing wrong? I get Invalid Memory Access when trying to pass the procedure.

Code: Select all

Procedure MyFunction(param.i)
  Debug param
EndProcedure

Prototype InitLib(*func)
Prototype LibFunc(param.i)

OpenLibrary(0, "test.dylib")

Global InitLib.InitLib = GetFunction(0, "Init")
Global LibFunc.LibFunc = GetFunction(0, "Func1")

InitLib(@MyFunction())
LibFunc(5)
Library

Code: Select all

Prototype HostFunc(param1.i)

Global HostFunc.HostFunc

Procedure Init(*func)
  HostFunc = *func
EndProcedure

Procedure Func1(param1.i)
  HostFunc(param1)
EndProcedure
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Call host program procedure from DLL?

Post by chi »

Try ProcedureDLL :wink:
Et cetera is my worst enemy
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: Call host program procedure from DLL?

Post by wombats »

Oops, stupid oversight. :oops:
Post Reply