Jump to content

VB dll function conversion


Recommended Posts

The following VB code is used to retrieve stock prices and symbols from a Fasttrack.dll. Can anyone offer any suggestions for converting this code to Autoit? In studying Auto help it appears to be combining a Function declare and a DllCall in one statement but I'm not sure. Thanks.

Declare Function FTgetIssue Lib "FastTrack" (ByVal sym As String, prices As Single) As Long

Link to comment
Share on other sites

The following VB code is used to retrieve stock prices and symbols from a Fasttrack.dll. Can anyone offer any suggestions for converting this code to Autoit? In studying Auto help it appears to be combining a Function declare and a DllCall in one statement but I'm not sure. Thanks.

Declare Function FTgetIssue Lib "FastTrack" (ByVal sym As String, prices As Single) As Long

Maybe something like this (untested):

Func FTGetIssue($sSymbol, $nPrices)
  Local $iPrices, $aResult

  $iPrices = _Lib_FloatToInt($nPrices)
  $aResult = DllCall("FastTrack", "long", "FTgetIssue", "str", $sSymbol, "int", $iPrices)
  Return $aResult[0]
EndFunc

Func _Lib_FloatToInt($nFloat)
  Local $tFloat, $tInt

  $tFloat  = DllStructCreate("float")
  $tInt    = DllStructCreate("int"  , DllStructGetPtr($tFloat))
  DllStructSetData($tFloat, 1, $nFloat)
  Return DllStructGetData($tInt, 1)
EndFunc
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Thank you Paul. That was a big help. I'm so close I can taste it but it's not working. Does anything stand out to you in the following code?

Func FTopen()
    Local $aResult
    $aResult = DllCall("FastTrack", "long","FTopen")
  Return $aResult
EndFunc


Func FTrebuildSymbols()
    Local $aResult1
        $aResult1 = DllCall("FastTrack", "long","FTrebuildSymbols")
  Return $aResult1
EndFunc

Func FTgetJulian($date)
    Local $aResult2
    
;$date = _Lib_FloatToInt($date)
    $aResult2 = DllCall("FastTrack", "long", "FTgetJulian", "int", $date)
  Return $aResult2[0]
EndFunc


Func FTgetNumDays($sym)
    Local $aResult3
    
    $aResult3 = DllCall("FastTrack", "long", "FTgetNumDays", "int", $sym)
  Return $aResult3[0]
EndFunc

Func FTgetStartDateBySym($sym)
    Local $aResult4
    
    $aResult4 = DllCall("FastTrack", "long", "FTgetStartDateBySym", "int", $sym)
  Return $aResult4[0]
EndFunc


Func FTGetIssue($sSymbol, $nPrices)
 Local $iPrices, $aResult5

  $iPrices = _Lib_FloatToInt($nPrices)
  $aResult5 = DllCall("FastTrack", "long", "FTgetIssue", "str", $sSymbol, "int", $iPrices)
  Return $aResult5[0]
EndFunc

Func _Lib_FloatToInt($nFloat)
  Local $tFloat, $tInt

  $tFloat  = DllStructCreate("float")
  $tInt = DllStructCreate("int"  , DllStructGetPtr($tFloat))
  DllStructSetData($tFloat, 1, $nFloat)
  Return DllStructGetData($tInt, 1)
EndFunc

Dim $nav[5050]
Dim $var, $start, $startday, $lastday



$fund = "rut-i"

$var = FTopen()
$var = FTrebuildSymbols()
$start=FTgetStartDateBySym($fund);:'the first day of data for symbol - array position
$startday=FTgetJulian($start);:'the first day of data for symbol - julian date
$lastday=FTgetJulian(FTgetNumDays($fund));:'the last day of data


$output = FTGetIssue($fund,$nav[1000])

MsgBox(4096, "Test", "result = "& $output, 10)
Edited by burger
Link to comment
Share on other sites

Thank you Paul. That was a big help. I'm so close I can taste it but it's not working. Does anything stand out to you in the following code?

Func FTopen()
    Local $aResult
    $aResult = DllCall("FastTrack", "long","FTopen")
  Return $aResult
EndFunc
Func FTrebuildSymbols()
    Local $aResult1
        $aResult1 = DllCall("FastTrack", "long","FTrebuildSymbols")
  Return $aResult1
EndFunc

Func FTgetJulian($date)
    Local $aResult2
    
;$date = _Lib_FloatToInt($date)
    $aResult2 = DllCall("FastTrack", "long", "FTgetJulian", "int", $date)
  Return $aResult2[0]
EndFunc
Func FTgetNumDays($sym)
    Local $aResult3
    
    $aResult3 = DllCall("FastTrack", "long", "FTgetNumDays", "int", $sym)
  Return $aResult3[0]
EndFunc

Func FTgetStartDateBySym($sym)
    Local $aResult4
    
    $aResult4 = DllCall("FastTrack", "long", "FTgetStartDateBySym", "int", $sym)
  Return $aResult4[0]
EndFunc
Func FTGetIssue($sSymbol, $nPrices)
 Local $iPrices, $aResult5

  $iPrices = _Lib_FloatToInt($nPrices)
  $aResult5 = DllCall("FastTrack", "long", "FTgetIssue", "str", $sSymbol, "int", $iPrices)
  Return $aResult5[0]
EndFunc

Func _Lib_FloatToInt($nFloat)
  Local $tFloat, $tInt

  $tFloat  = DllStructCreate("float")
  $tInt = DllStructCreate("int"  , DllStructGetPtr($tFloat))
  DllStructSetData($tFloat, 1, $nFloat)
  Return DllStructGetData($tInt, 1)
EndFunc

Dim $nav[5050]
Dim $var, $start, $startday, $lastday
$fund = "rut-i"

$var = FTopen()
$var = FTrebuildSymbols()
$start=FTgetStartDateBySym($fund);:'the first day of data for symbol - array position
$startday=FTgetJulian($start);:'the first day of data for symbol - julian date
$lastday=FTgetJulian(FTgetNumDays($fund));:'the last day of data
$output = FTGetIssue($fund,$nav[1000])

MsgBox(4096, "Test", "result = "& $output, 10)
1. Where are you setting $nav[1000]?

2. Put some code to show @Error after FTGetIssue to see if it's a problem with the DllCall structure. If it's not, then the -999 is a valid return result from the Dll and you'd need to find out what that means.

I don't have this Dll, so I can't test for you. :)

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Your #1 is on the right track. How do I convert this?

DEF nav[5040]:float

FTGetIssue accepts a float value as the parameter for $nPrices. However, I do not see anywhere in the script that you posted where you are setting the value in $nav[1000]. If you check @Error right after the call to FTGetIssue and it is 0, then there is nothing wrong with the Dll call itself. However, you may be passing the wrong values to the call and since we don't have the Dll (or the documentation that goes with it), you'll have to debug this part yourself. I have no idea what $nPrices is even suppose to be, other than a float value. :)
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I agree it appears that nav[x] is not declared however in the VB version it produces the desired result as you see it here. Changing x produces varying results as needed. I assumed that the DLL was doing the work behind the scenes but I'm way over my head with dll's. (The @error checks out fine.) The only missing piece that I can find is the DEF which in VB declares nav[] to be a float variable like $nPrices. I assumed this wasn't nessesary since FloatToInt converted $nPrices to Integer.

$output = FTGetIssue($fund,$nav[1000])

MsgBox(4096, "Test", "result = "& $nav[45], 10)

This is the corrected output stmt. The top line defines $nav[x] based on $fund. At least that is how it works in VB.

Edited by burger
Link to comment
Share on other sites

I agree it appears that nav[x] is not declared however in the VB version it produces the desired result as you see it here. Changing x produces varying results as needed. I assumed that the DLL was doing the work behind the scenes but I'm way over my head with dll's. (The @error checks out fine.) The only missing piece that I can find is the DEF which in VB declares nav[] to be a float variable like $nPrices. I assumed this wasn't nessesary since FloatToInt converted $nPrices to Integer.

$output = FTGetIssue($fund,$nav[1000])

MsgBox(4096, "Test", "result = "& $nav[45], 10)

This is the corrected output stmt. The top line defines $nav[x] based on $fund. At least that is how it works in VB.

That would have been nice to know during your first post. :) Change what I gave you to this and give it a try:

Func FTGetIssue($sSymbol, ByRef $nPrices)
  Local $aResult

  $aResult = DllCall("FastTrack", "long", "FTgetIssue", "str", $sSymbol, "int", 0)
  $nPrices = _Lib_IntToFloat($aResult[2])
  Return $aResult[0]
EndFunc

Func _Lib_IntToFloat($iInt)
  Local $tFloat, $tInt

  $tInt   = DllStructCreate("int")
  $tFloat = DllStructCreate("float", DllStructGetPtr($tInt))
  DllStructSetData($tInt, 1, $iInt)
  Return DllStructGetData($tFloat, 1)
EndFunc
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Nada. I see you switch FloattoInt to InttoFloat. Was this intentional? If not and we are converting a float to an int, does this round off digit beyond the decimal?

I'm doing the best I can based on the limited about of info you're giving me. You stated previously that $nPrices was a output variable in the function, not an input variable. I changed the code accordingly. Are you checking $nPrices after the DllCall? Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I'm doing the best I can based on the limited about of info you're giving me. You stated previously that $nPrices was a output variable in the function, not an input variable. I changed the code accordingly. Are you checking $nPrices after the DllCall?

Sorry. My ignorance is showing. I assumed float / int referred to variable types. I did not know they dealt with input vs output.

Immediately after the DllCall line, it's fine. If I check it after the following line, it is 0.

$nPrices = _Lib_IntToFloat($aResult[2])

Link to comment
Share on other sites

Sorry. My ignorance is showing. I assumed float / int referred to variable types. I did not know they dealt with input vs output.

Immediately after the DllCall line, it's fine. If I check it after the following line, it is 0.

$nPrices = _Lib_IntToFloat($aResult[2])

Ugh. I'm getting a headache. Ok, here is what you gave me:

Declare Function FTgetIssue Lib "FastTrack" (ByVal sym As String, prices As Single) As Long

The first code that I gave you assumed that "sym" was an input string and "prices" was an input float. You then told me that "prices" is an output parameter. So what I need you to do is run the second bit of code that I gave you in SciTE like this:

Global $iResult, $nPrice
$iResult = FTGetIssue("rut-i", $nPrice)
ConsoleWrite("Result: " & $iResult)
ConsoleWrite("Price.: " & $nPrice)

and then post what got written to the console.

Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Result: -999Price.: 0+>16:44:09

Well, I guess I'll have to do all the work myself then. I went to the fast track web site and read the documentation for the Dll you're trying to use. You might want to take some time to read it yourself here. The function that you are trying to implement returns an array of float values, not a single float. This array needs to be built with a call to FTGetMaxNumDays too. There is a bunch of other stuff that you should pay attention to also, like the return value of FTOpen. Here's as far as I got before I lost interest:

Global $iI, $iDays, $tPrices, $iResult

;
; Open FastTrack Dll here
;
$iDays   = FTGetMaxNumDays()
$tPrices = DllStructCreate("float[" & $iDays & "]")
$iResult = FTGetIssue("rut-i", DllStructGetPtr($tPrices))
ConsoleWrite("Result: " & $iResult)
for $iI = 1 to $iDays
  ConsoleWrite("Price " & $iI & ": " & DllStructGetData($tPrices, 1, $iI))
next

Func FTGetIssue($sSymbol, $pPrices)
  Local $aResult

  $aResult = DllCall("FastTrack", "long", "FTgetIssue", "str", $sSymbol, "ptr", $pPrices)
  if $aResult = 0 then
    ConsoleWrite("FTGetIssue returned " & $aResult[0])
    Exit
  endif
  Return $aResult[0]
EndFunc

Func FTGetMaxNumDays()
  Local $aResult

  $aResult = DllCall("FastTrack", "long", "FTgetMaxNumDays")
  if $aResult < 0 then
    ConsoleWrite("FTGetMaxNumDays returned " & $aResult[0])
    Exit
  endif
  Return $aResult[0]
EndFunc
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Well, I guess I'll have to do all the work myself then. I went to the fast track web site and read the documentation for the Dll you're trying to use. You might want to take some time to read it yourself here. The function that you are trying to implement returns an array of float values, not a single float. This array needs to be built with a call to FTGetMaxNumDays too. There is a bunch of other stuff that you should pay attention to also, like the return value of FTOpen. Here's as far as I got before I lost interest:

Global $iI, $iDays, $tPrices, $iResult

;
; Open FastTrack Dll here
;
$iDays   = FTGetMaxNumDays()
$tPrices = DllStructCreate("float[" & $iDays & "]")
$iResult = FTGetIssue("rut-i", DllStructGetPtr($tPrices))
ConsoleWrite("Result: " & $iResult)
for $iI = 1 to $iDays
  ConsoleWrite("Price " & $iI & ": " & DllStructGetData($tPrices, 1, $iI))
next

Func FTGetIssue($sSymbol, $pPrices)
  Local $aResult

  $aResult = DllCall("FastTrack", "long", "FTgetIssue", "str", $sSymbol, "ptr", $pPrices)
  if $aResult = 0 then
    ConsoleWrite("FTGetIssue returned " & $aResult[0])
    Exit
  endif
  Return $aResult[0]
EndFunc

Func FTGetMaxNumDays()
  Local $aResult

  $aResult = DllCall("FastTrack", "long", "FTgetMaxNumDays")
  if $aResult < 0 then
    ConsoleWrite("FTGetMaxNumDays returned " & $aResult[0])
    Exit
  endif
  Return $aResult[0]
EndFunc
Thanks. That is producing results. I greatly appreciate your help and I apologize for time waste. I coded this several years ago in a simple language called iBasic. It probably did me more harm than good.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...