Sign in to follow this  
Followers 0
Nezoic

Need Help DLL/Structures

4 posts in this topic

#1 ·  Posted (edited)

I'm trying to understand how DLL calls and Structures work. I decided to start with something simple like system time.(if it actually is simple).

I've tried understanding the dozens of other DLL calls in various UDF through this board, and altho they seam to make a little sense I just cannot grasp the full logic of them. If anyone could offer anymore explanation of the following code and set me on the right path I would appreciate it.

;System time test
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtime.asp
;MSDN - GetSystemTime
;
;void GetSystemTime(
;  LPSYSTEMTIME lpSystemTime ;Pointer to SYSTEMTIME
;);

;typedef struct _SYSTEMTIME {  
;WORD wYear;  
;WORD wMonth;  
;WORD wDayOfWeek;  
;WORD wDay;  
;WORD wHour;  
;WORD wMinute;  
;WORD wSecond;  
;WORD wMilliseconds;
;} SYSTEMTIME, 



$_stimestr = "WORD;WORD;WORD;WORD;WORD;WORD;WORD;WORD"
$SYSTEMTIME = DllStructCreate($_stimestr)

$t = DllCall("kernel32.dll", "", "GetSystemTime", "", $SYSTEMTIME)

msgbox(0, "System Time", $t)

I know I'm missing something, and I would guess the actual data in the structure. Where does this data come from within the system?

Also I'm sure my formating is incorrect, was just trial and erroring when I decide to post this :)

Edited by Nezoic

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If anyone could offer anymore explanation of the following code and set me on the right path I would appreciate it.

You've do have got a few problems with it. :)

1) $_stimestr = "WORD;WORD;WORD;WORD;WORD;WORD;WORD;WORD"

There is no such specifier like WORD. Legal specifiers are named in AI's Help, in a list under the "DllCall" explanation. In your case you need "short" (a 16-bit integer).

2) When calling the DLL-function you have left both the return-type as well as the (single) argument-type specifiers empty. Currently the return-type one needs to be "none", and the argument-type "ptr" (you are supplying it a ponter to a structure, not the structure itself). This leads to the next problem :

3) You need to provide the structure to the actual DLL-call with another command, being "DllStructGetPtr"

4) You need to retrieve the results outof the structure with yet another command, being "DllStructGetData"

Everything combined could result in code looking like this :

$SYSTEMTIME = DllStructCreate("short;short;short;short;short;short;short;short")

DllCall("kernel32.dll", "none", "GetSystemTime", "ptr",DllStructGetPtr($SYSTEMTIME))

msgbox(0, "System Time", "Date: "&DllStructGetData($SYSTEMTIME,1)&"-"& _
  DllStructGetData($SYSTEMTIME,2)&"-"& _
  DllStructGetData($SYSTEMTIME,4)&chr(13)& _
  "Day : "&DllStructGetData($SYSTEMTIME,3)&chr(13)& _
  "Time : "&DllStructGetData($SYSTEMTIME,5)&":"& _
  DllStructGetData($SYSTEMTIME,6)&"."& _
  DllStructGetData($SYSTEMTIME,7) _
)
Hope that helps. Edited by BitRot

Share this post


Link to post
Share on other sites

Excellent. That explains a lot. I was under the impression that you would have to point the structure to something else as well, instead of just declaring the data type.

Thank you very much.

Share this post


Link to post
Share on other sites

Thank you very much.

You're welcome :lmao:

Share this post


Link to post
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
Sign in to follow this  
Followers 0