Author Topic: Calling a Oxygen DLL function using function pointer seems not working  (Read 1406 times)

0 Members and 1 Guest are viewing this topic.

erosolmi

  • Guest
Ciao Charles,

I'm trying to use Oxygen to develop thinBasic modules.
I have problem calling from a PowerBasic program a function inside an Oxygen DLL having just the function pointer.

Here the example and attached the needed files to test.
Do not know what I'm doing wrong, maybe it is just under my nose :)

Oxygen source of the DLL.
GiveMeTheFunctionPTR is exported and is used to pass to the PB executable the pointer to Exec_Hello function

Code: [Select]
  '
  $dll
  $filename "Call_DWORD_Hang.dll"
  #include "..\..\inc\RTL32.inc"

    '----------------------------------------------------------------------------
    Function  GiveMeTheFunctionPTR() As sys Export
      Function = (@Exec_Hello)
    end function


    function Exec_Hello() as long
        print "Hello"
    end function



PowerBasic source of executable calling the DLL.
It calls GiveMeTheFunctionPTR  from the DLL and if ok, it will CALL DWORD ... using a function template
It hangs at CALL DWORD ...

Code: [Select]
  #Compile Exe
  Declare Function Exec_CODEPTR_ReturnLong() As Long
  Declare Function GiveMeTheFunctionPTR Lib "Call_DWORD_Hang.dll" Alias "GiveMeTheFunctionPTR" () As Dword

  Function PBMain() As Long
    Local pFun              As Dword
    Local tmpReturnCodeLong As Long
   
    pFun = GiveMeTheFunctionPTR()
    MsgBox "Pointer to function is:" & Str$(pFun)

    If pFun Then
      MsgBox "Before calling"
        Call Dword pFun Using Exec_CODEPTR_ReturnLong() To tmpReturnCodeLong
      MsgBox "After calling"
    End If
   
  End Function
 

Thanks a lot for any help.

Ciao
Eros

JRS

  • Guest
Taking a peek at DLLC might help.

Something to keep you busy until Charles solves your problem.  :)

Charles Pegge

  • Guest

Ciao Eros,

All you need to do is make your hello function extern, since this is being exported indirectly. Extern functions save additional registers on the stack, complying with stdcall / cdecl

Code: [Select]
  $dll
  $filename "Call_DWORD_Hang.dll"
  #include "$\inc\RTL32.inc"

  extern
   
    '----------------------------------------------------------------------------
    Function  GiveMeTheFunctionPTR() As sys, Export
      Function = (@Exec_Hello)
    end function


    function Exec_Hello() as long
        print "Hello"
    end function

  end extern

erosolmi

  • Guest
Perfect.

Thanks a lot

Eros