Jump to content

DllCall & datatypes


Iczer
 Share

Recommended Posts

I have some troubles understanding data types of returned by my freebasic dll values :

Function Time_GetCurrentISOWeekNumber_Orig() should return String value (two digits), but actually return "ђЖ¤"

Function Time_GetCurrentISOWeekNumber() is working as intended

Why STR value not recognized by Autoit or, it seems, have first bytes of string replaced by something (maybe BOM?)

Freebasic dll code:

Spoiler
#include once "vbcompat.bi"
#include once "string.bi"
'==========================================================================================
Extern "Windows-MS"
'==========================================================================================
Public Function Time_GetCurrentISOWeekNumber() As wString Ptr Export
    Dim As Double d = Now()
    Dim As String * 8 WeekISO = Format(DatePart("ww", d, fbMonday, fbFirstFourDays),"00")
    Return WinAPI_MultiByteToWideChar(65001, StrPtr(WeekISO))
End Function
'==========================================================================================
Public Function Time_GetCurrentISOWeekNumber_Orig() As String Export
    Dim As Double d = Now()
    Dim As String * 8 WeekISO = Format(DatePart("ww", d, fbMonday, fbFirstFourDays),"00")
    Return WeekISO
End Function
'==========================================================================================
End Extern
'==========================================================================================

 

 

Autoit code:

Spoiler
#include <Date.au3>

Global $hDLL = DllOpen($sPathTocDLL)

ConsoleWrite(Time_GetCurrentISOWeekNumber() & @CRLF)
ConsoleWrite(Time_GetCurrentISOWeekNumber_Orig() & @CRLF)
ConsoleWrite(_WeekNumberISO () & @CRLF)

;==============================================================================================================================================================================================
Func Time_GetCurrentISOWeekNumber()

    Local $aRet = DllCall($hDLL,"WSTR*","Time_GetCurrentISOWeekNumber")
    If @error Then Return SetError(1000 + @error, 1000 + @extended,False)

    Return $aRet[0]

EndFunc
;==============================================================================================================================================================================================
Func Time_GetCurrentISOWeekNumber_Orig()

    Local $aRet = DllCall($hDLL,"STR","Time_GetCurrentISOWeekNumber_Orig")
    If @error Then Return SetError(1000 + @error, 1000 + @extended,False)

    Return $aRet[0]

EndFunc
;==============================================================================================================================================================================================

 

 

 

Link to comment
Share on other sites

I think that dlls that return strings do not play nice with autoit and probably any other language.

You will notice windows api functions mostly require caller to pass it a buffer to fill if you want a string from it.

I believe that is the crux of you issue.

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hello. Try this.

Func Time_GetCurrentISOWeekNumber_Orig()
    Local $aRet = DllCall($hDLL, "ptr", "Time_GetCurrentISOWeekNumber_Orig")
    If @error Then Return SetError(1000 + @error, 1000 + @extended, False)
    Return DllStructGetData(DllStructCreate("char[2]", DllStructGetData(DllStructCreate("ptr", $aRet[0]), 1)), 1)
EndFunc   ;==>Time_GetCurrentISOWeekNumber_Orig

Saludos

Link to comment
Share on other sites

8 hours ago, jguinch said:

I really think Danyfirex has some magical powers... 

Yes I have but not sure if it's magical. I destroy everything I touch (This is my gift, My curse)  lol

 

27 minutes ago, Iczer said:

Wow! Thanks! Simple string in freebasic not as simple as it sound it seems. :graduated::)

 

 

It it not so hard.  the unicode version you return a Pointer to string (wString Ptr Export)  for that you can use wstr as return in the dllcall.

The other one you return a string only for that you get a pointer to a pointer that points to a string lol. that's how I see it. maybe if you use something like  String Ptr Export it works. I'm not sure because I dont know freebasic. But it should be something like that I think.

 

Saludos

 

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...