Jump to content

Structres for DLLs


Ejoc
 Share

Recommended Posts

I don't think many people realize how simple objects are laid out in memory, particularly C-style structures.  I've been wanting to work on something like this for awhile, but I'm lazy.  At the moment, though, I have been working on some design ideas.  My goal is a bit more ambitious than yours, so its pretty complicated.  The actual coding for my idea shouldn't be too hard, but coming up with a good design that fits together and that I'm satisfied with is.  This is a lot more fun than what I worked on previously (And put to the side for awhile), which was PE Header stuff...  :)

<{POST_SNAPBACK}>

I like your Ambitious project. My request would be "can you give us a pointer to it so we can pass it to dll calls" :D
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I like your Ambitious project.  My request would be "can you give us a pointer to it so we can pass it to dll calls" :)

<{POST_SNAPBACK}>

You know, I've been thinking. I think my ambitious idea may be too much for AutoIt. Looking at it and thinking about how it would be used, I'm afraid its too much for DllCall. I know people will try to use it to make AutoIt a typed language, despite that not being what the feature would be added for. My idea was to basically abstract away the index your method uses. By putting a gloss on it to make it look similar to the standard member access notation, I thought it might make things easier. However, thinking about it, it also gives the illusion that user-defined types can be created, which is not the case.

So, with the idea of providing a member access operator scratched, I'd basically be re-implementing your code. I don't really think thats necessary, so I'm just going to stop my work since you've already gotten this far.

Link to comment
Share on other sites

You know, I've been thinking.  I think my ambitious idea may be too much for AutoIt.  Looking at it and thinking about how it would be used, I'm afraid its too much for DllCall.  I know people will try to use it to make AutoIt a typed language, despite that not being what the feature would be added for.  My idea was to basically abstract away the index your method uses.  By putting a gloss on it to make it look similar to the standard member access notation, I thought it might make things easier.  However, thinking about it, it also gives the illusion that user-defined types can be created, which is not the case.

So, with the idea of providing a member access operator scratched, I'd basically be re-implementing your code.  I don't really think thats necessary, so I'm just going to stop my work since you've already gotten this far.

<{POST_SNAPBACK}>

I feel kinda guilty :)
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

If Opt('MustDeclareVars',1) is used the following happens

C:\Program Files\AutoIt3\Include\DllMem.au3 (339) : ==> Variable used without being declared.:

$iIndex = _DllMemElementOffset($szStruct,$iElement)

^ ERROR

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I was thinking, and wanted to run this by people. What about a function that would read each element into an array.

Something like:

$array = _DllMemGetStruct($p,"int;int;char(128)")

Then array would hold:

$array[0] = 0

$array[1] = 0

$array[2] = "Some Null Terminated String"

Could possibly add a Set version too...

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

I was thinking, and wanted to run this by people.  What about a function that would read each element into an array.

Something like:

$array = _DllMemGetStruct($p,"int;int;char(128)")

Then array would hold:

$array[0] = 0

$array[1] = 0

$array[2] = "Some Null Terminated String"

Could possibly add a Set version too...

<{POST_SNAPBACK}>

Its certainly not necessary, but in many (probably most) cases it will make code much more readable than using _DLLMemGet. :)

601DisengageEnd Program

Link to comment
Share on other sites

The one thing that concerns me is how to handle:

$struct = "int(32);char(128);byte(128)"

What should the array hold in this case....

<{POST_SNAPBACK}>

Ugh... large. 161 elements. Since you differentiate between char and byte imho it should be safe to assume char(128) is a string. If its not, byte should have been specified. Its up to the caller to make the correct choices.

601DisengageEnd Program

Link to comment
Share on other sites

I was looking forward to using it, but now its dead

<{POST_SNAPBACK}>

Here was my thinking on why I decided to stop.

Thinking about the design, I realized it was going to be a significant amount of code to accomplish what I wanted for such a relatively "small" feature. Adding advanced support for creating "types" that could only be used with a single function seemed excessive. It also gave an illusion that types were supported, which would not be the case. It would only be an eloquent way to describe C-style structures for use in DllCall(). However, knowing how people misappropriate things and do dumb things as a result, I realized that perhaps making it too easy would cause more harm than good. Although to anybody with some C/C++ experience, the notation and the convenience provided would be nice, to those who don't know any better, they would be trying to use it as a type builder, which it would not be.

Since you had already started working on something combined with my newfound doubts in people actually using it correctly along with the volume of code for a simple feature, I decided it would be best to just abort before I wasted any more time on something that was just going to be mostly bloat and problems later on. Although it would be nice, its not necessary. A simple index based approach which is what your method appers to be (I haven't tried your stuff, only looking at the examples posted) is more than enough.

Link to comment
Share on other sites

How's this for a tease Larry?

Anyone wanna use your Joystick in AutoIt?

#cs
vi:ts=4 sw=4:
typedef struct joyinfoex_tag { 
    DWORD dwSize; 
    DWORD dwFlags; 
    DWORD dwXpos; 
    DWORD dwYpos; 
    DWORD dwZpos; 
    DWORD dwRpos; 
    DWORD dwUpos; 
    DWORD dwVpos; 
    DWORD dwButtons; 
    DWORD dwButtonNumber; 
    DWORD dwPOV; 
    DWORD dwReserved1; 
    DWORD dwReserved2; 
} JOYINFOEX; 
#ce
Opt("MustDeclareVars",1)
#include <DllMem.au3>
#include <GUIConstants.au3>

Local $JOYINFOEX_struct = "dword(13)"
Local $joy,$coor,$h,$s,$msg

$joy    = _JoyInit()

GUICreate("Joystick Test",300,300)
$h= GuiCtrlCreatelabel("",10,10,290,290)
GUISetState()

while 1
    $msg    = GUIGetMSG()
    $coor   = _GetJoy($joy,0)
    $s      = "Joystick(0):" & @CRLF & _
                "X: " & $coor[0] & @CRLF & _
                "Y: " & $coor[1] & @CRLF & _
                "Z: " & $coor[2] & @CRLF & _
                "R: " & $coor[3] & @CRLF & _
                "U: " & $coor[4] & @CRLF & _
                "V: " & $coor[5] & @CRLF & _
                "POV: " & $coor[6] & @CRLF & _
                "Buttons: " & $coor[7]
    GUICtrlSetData($h,$s,1)
    sleep(10)
    if $msg = $GUI_EVENT_CLOSE Then Exitloop
WEnd


;======================================
;   _JoyInit()
;======================================
Func _JoyInit()
    Local $joy

    $joy    = _DllMemCreate($JOYINFOEX_struct)
    if Not $joy Then Return 0
    _DllMemSet($joy,$JOYINFOEX_struct,0,_DllMemStructSize($JOYINFOEX_struct),0)
    _DllMemSet($joy,$JOYINFOEX_struct,0,255,1)
    return $joy
EndFunc

;======================================
;   _GetJoy($lpJoy,$iJoy)
;   $lpJoy  Return from _JoyInit()
;   $iJoy   Joystick # 0-15
;   Return  Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV
;           Buttons down
;
;           *POV This is a digital game pad, not analog joystick
;           65535   = Not pressed
;           0       = U
;           4500    = UR
;           9000    = R
;           Goes around clockwise increasing 4500 for each position
;======================================
Func _GetJoy($lpJoy,$iJoy)
    Local $coor,$ret

    Dim $coor[8]
    $ret = DllCall("Winmm.dll","int","joyGetPosEx",_
                    "int",$iJoy,_
                    "ptr",$lpJoy)
    if Not @error Then
        $coor[0]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,2)
        $coor[1]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,3)
        $coor[2]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,4)
        $coor[3]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,5)
        $coor[4]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,6)
        $coor[5]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,7)
        $coor[6]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,10)
        $coor[7]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,8)
    EndIf

    return $coor
EndFunc
Edited by Ejoc
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

I'm closing down _DllMem, I'm going to try integrating into a beta of AutoIt then an extra dll wouldn't be required, and should provide improved execution times... So I wont be working on _DllMem anymore. Hopefully at some point there will be a new and improved substitue to it.

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
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...