How to get values via ByRef parameter of a DLL Function

How to get values via ByRef parameter of a DLL Function

Postby RAMESHBABU » Mon Sep 21, 2009 3:23 pm

Hi All,

The following code working Ok in VB.

Code: Select all  Expand view

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: Select all  Expand view

DLL32 Function GetDeviceTime(nHandleIndex AS LONG, nTotalCount AS LONG, pnDateTime AS STRING) AS LONG PASCAL LIB hLib
 


and

When I called as under:

Code: Select all  Expand view


#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
Last edited by RAMESHBABU on Tue Sep 22, 2009 6:22 am, edited 1 time in total.
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India


Re: How to translate Data types of VB in FWH+xHarbour

Postby RAMESHBABU » Mon Sep 21, 2009 4:40 pm

Hello Mr.Enrico,

Thanks for your attention.

I tried your suggestion with no result.

Regards,

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to translate Data types of VB in FWH+xHarbour

Postby Enrico Maria Giordano » Mon Sep 21, 2009 5:03 pm

What value are you passing as nHandleIndex?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to translate Data types of VB in FWH+xHarbour

Postby RAMESHBABU » Mon Sep 21, 2009 5: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: Select all  Expand view


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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to get values via ByRef parameter of a DLL Function

Postby RAMESHBABU » 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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to get values via ByRef parameter of a DLL Function

Postby Enrico Maria Giordano » Tue Sep 22, 2009 3:54 pm

Try

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


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 76 guests