FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to get values via ByRef parameter of a DLL Function
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to get values via ByRef parameter of a DLL Function
Posted: Mon Sep 21, 2009 03:23 PM
Hi All,

The following code working Ok in VB.

Code (fw): Select all Collapse
Public Declare Function GetDeviceTime Lib "DeviceLib" (ByVal nHandleIndex As Long, ByRef nTotalCount As Long, ByRef pnDateTime As Date) As Long


To call the same function in our FWH, I wrote the code as under:

Code (fw): Select all Collapse
DLL32 Function GetDeviceTime(nHandleIndex AS LONG, nTotalCount AS LONG, pnDateTime AS STRING) AS LONG PASCAL LIB hLib


and

When I called as under:

Code (fw): Select all Collapse
#include "fivewin.ch"

FUNCTION main()

LOCAL nTotalCount  := 0
LOCAL pnDateTime := SPACE(19)     // 9999-99-99 99:99:99

GetDeviceTime(nHandleIndex, @nTotalCount @pnDateTime)
?nTotalCount, pnDateTime

RETURN nil


I am not getting the Referenced date type variable populated with correct value and getting some junk characters.

Not only Date type, even (LONG) type of referenced parameters are not returning correct values but
returning only the Initial values originally assigned to them at the the time of their declaration.

Can anybody help me please.

Thanks,

- Ramesh Babu P
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to translate Data types of VB in FWH+xHarbour
Posted: Mon Sep 21, 2009 04:33 PM
Try

Code (fw): Select all Collapse
@nTotalCount AS PTR


EMG
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: How to translate Data types of VB in FWH+xHarbour
Posted: Mon Sep 21, 2009 04:40 PM

Hello Mr.Enrico,

Thanks for your attention.

I tried your suggestion with no result.

Regards,

  • Ramesh Babu P
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to translate Data types of VB in FWH+xHarbour
Posted: Mon Sep 21, 2009 05:03 PM

What value are you passing as nHandleIndex?

EMG

Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: How to translate Data types of VB in FWH+xHarbour
Posted: Mon Sep 21, 2009 05:26 PM
Hi Enrico,

>>What value are you passing as nHandleIndex?

I have a 3rd party DLL and as per the documentation I am calling a function as under:
Code (fw): Select all Collapse
hLib := LoadLib32("fka.dll")
nHandleIndex := ConnectUSB(1, 123456)

IF nHandleIndex = 1 //RUN_SUCESS
   MsgInfo("The Device is connected.")
ELSE
   MsgInfo("Sorry. The Device is not connected.")
   RETURN nil
ENDIF


Expect the ByVal all other functions mentioned in the documentation of the DLL is working fine.

I am currently having problems only with the parameters passed by reference in functions
provided in the DLL. They are not returning the actual values other than the initial values
assigned at their declaration.

Regards,

- Ramesh Babu P
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: How to get values via ByRef parameter of a DLL Function
Posted: Tue Sep 22, 2009 12:34 PM

Mr.Enrico,

As usually you have helped this time also from a big problem.
Your solution worked very well.

I did not put '@' before DLL FUNCTION variables earlier. Thats the
reason, I have come this forum for solution.

But I still have problem with the DataTime String variable. I am
getting some binary characters junk. The DLL Provider's DateTime format is
yyyy-mm-dd hh:mm:ss.

But when I am calling the value by reference I am not getting proper values.
What is the correct data type I should use with AS orgument while calling
the DLL FUNCTION to get the correct value.

All Numeric values are properly shown with 'AS PTR'

Can you please suggest a way out to this also.

Regards,

  • Ramesh Babu P
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to get values via ByRef parameter of a DLL Function
Posted: Tue Sep 22, 2009 03:54 PM
Try

Code (fw): Select all Collapse
DLL32 Function GetDeviceTime(nHandleIndex AS LONG, @nTotalCount AS PTR, @pnDateTime AS LPSTR) AS LONG PASCAL LIB hLib


EMG

Continue the discussion