Skip to content

Commit

Permalink
Merge pull request maul-esel#17 from Uberi/gh-pages
Browse files Browse the repository at this point in the history
Add section to DllCall post
  • Loading branch information
maul-esel committed Feb 11, 2012
2 parents 1e01111 + c7b69a0 commit f3673d7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion en/_posts/2011-11-24-DllCalls.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Working with Windows API
title: Working with external functionality
layout: post
permalink: /en/DllCalls.html
---
Expand Down Expand Up @@ -105,3 +105,25 @@ IDCANCEL := 2 ; define the constant as pointed out on msdn
if (result == IDCANCEL)
MsgBox You canceled.
{% endhighlight %}

### Exported data
Rarely, DLLs may export variables in addition to functions; for example, the Raydium Game Engine DLL. Although it is not possible to retrieve or store values to this variable directly using DllCall(), it is possible to use the [GetProcAddress()](http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212.aspx) WinAPI function to do so:
{% highlight ahk linenos %}; any AutoHotkey version

;compatibility types
UPtr := A_PtrSize ? "UPtr" : "UInt"
AStr := A_IsUnicode ? "AStr" : "Str"

;load the library that contains the exported variable
hModule := DllCall("LoadLibrary","Str","Raydium.dll",UPtr)

;obtain the address of the variable "raydium_joy_x"
pJoystickX := DllCall("GetProcAddress",UPtr,hModule,AStr,"raydium_joy_x",UPtr)

;retrieve a float value from the address
JoyStickX := NumGet(pJoystickX + 0,0,"Float")
MsgBox, The joystick position in the x-axis is currently %JoystickX%.

;store a float value in the memory location pointed to by the address
NumPut(0.8,pJoystickX + 0,0,"Float") ;store 0.8 as the value
{% endhighlight %}

0 comments on commit f3673d7

Please sign in to comment.