AutoHotkey Community

It is currently May 27th, 2012, 2:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: February 7th, 2010, 11:02 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Hi,

I'm sure it has been asked thousand times. But I can't find a tutorial how to do it. Sorry.
I have a DLLCall that expects an struct:
Code:
typedef struct {
    char *name;
    char *driver;
    DWORD flags;
} BASS_DEVICEINFO;
How do i calculate the right Capacity? And how do I afterwards get the data with NumGet() out of it? Thanks.

If you know a tutorial on structs in AHK, please point me to it.

_________________
Ciao
toralf
Image


Last edited by toralf on February 8th, 2010, 7:01 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2010, 11:24 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I found one tutorial: http://www.autohotkey.com/forum/topic35843.html
But I'm not so sure I understood.

Here is what i THINK the code is supposed to be...

Since in the struct are two pointers for strings and one is an integer, the capacity should be 12 (3*4)
Code:
VarSetCapacity(BASS_DEVICEINFO,12)


Then the DLL is called with the address of the BASS_DEVICEINFO struct
Code:
DllCall(BASS_DLLPATH . BASS_DLL . "\BASS_GetDeviceInfo", UInt, device, UInt, &BASS_DEVICEINFO)


The pointers to the strings and the number can then be retrieved with NumGet from the struct
Code:
pName := NumGet( BASS_DEVICEINFO+0 , 0, "UInt" )
pDriver := NumGet( BASS_DEVICEINFO+4 , 0, "UInt" )
Flags := NumGet( BASS_DEVICEINFO+8 , 0, "UInt" )
Unfortunately that doesn't work. :|
Any help?

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2010, 11:59 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
Do the pointers returned in that struct point to memory locations inside your script's memory space or elsewhere?

I'm guessing that those strings are in some other process an you'll need ReadProcessMemory to get them.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2010, 12:11 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Could be. I'm not sure.
The DLL is loaded with the AHL script.
How could I test this?

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2010, 12:30 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Moin,

wenn es ANSI ist, probier mal sowas / if it is ANSI, you might try something like this:
Code:
pName := NumGet(BASS_DEVICEINFO, 0, "UInt")
pDriver := NumGet(BASS_DEVICEINFO, 4, "UInt")
Flags := NumGet(BASS_DEVICEINFO , 8, "UInt")

VarSetCapacity(Name, DllCall("lstrlenA", Uint, pName) + 1, 0)
DllCall("lstrcpyA", Str, Name, Uint, pName)
MsgBox, %Name%


_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2010, 1:04 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Thanks a lot,
That solved it.

Is there a shorter way to do it?
It seems to be quite complicated.
First to create a Var with a capacity of the string length the pointer is pointing at.
Then copying the string the pointer is pointing at into the var.

If not, I can live with it.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2010, 10:21 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
You could always create a function to retrieve the string. Here's a trick:
Code:
StrGetA(p) {
    return DllCall("MulDiv", "int", p, "int", 1, "int", 1, A_IsUnicode ? "astr":"str")
}
MulDiv returns p as-is, but DllCall sees the return type is "str" so interprets the return value (p) as a string pointer.
Code:
VarSetCapacity(bdi, 12, 0)
if !DllCall("LoadLibrary", "str", "bass.dll")
|| !DllCall("bass\BASS_GetDeviceInfo", "uint", 1, "uint", &bdi)
    ExitApp

MsgBox % "
(
name: "   StrGetA(NumGet(bdi,0)) "
driver: " StrGetA(NumGet(bdi,4)) "
flags: "          NumGet(bdi,8)
)
Tested okay with AutoHotkey v1.0.48.05 and ANSI/Unicode builds of AutoHotkey_L. (Btw, AutoHotkey_L and AutoHotkeyU have StrGet() built-in, but it is currently incapable of retrieving ANSI strings in Unicode builds.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2010, 7:00 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Thanks a lot Lexikos. DllCall are not my cup of tea....

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 2:19 am 
toralf wrote:
That solved it.

...instead of simply marking this solved, could someone create or point me to current struct handling info/code? I know there's ahkstructlib, last I checked no one has updated it in a while...is that currently the best option?...still?...would someone please make a full struct handling API? I don't like using NumGet() directly, cuz you need to know the offsets...plus most structs have LPSTR fields, then you only have a pointer to a string & need to do "something else" to get/set that string...I'm pretty good savvy with AutoHotkey/computers, but structs have been giving me fits for years...MSDN or Google will tell me a struct field is LPSTR (or DWORD) & in NumGet() I'm supposed to know to use UInt or <whatever>? what about LPCSTR? is that UInt too?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2010, 4:22 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Have a look at this ---> Easy WinAPI - WinAPI Parser, DllCall with single hotkey :?:

_________________
My Ahk Site


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2010, 4:40 am 
Thanks, but no source makes it less-than-useful. Anything else?...with source?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2010, 7:04 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Did you see this part?

Easy WinAPI - WinAPI Parser, DllCall with single hotkey wrote:
Limitations
. . .
3) It does not parse structs. use Lexiko's StructParser or corrupt's ahkStructLib2 together

And they both have source :)

_________________
My Ahk Site


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2010, 2:38 pm 
a_h_k wrote:
Did you see this part?

...yes, I know about StructParser (& that's actually pretty helpful {it's just not a Struct API}) & I already mentioned that I know about ahkstructlib. Maybe I'll smash them together & try to make my own version of struct-handling code? So I guess the answer is no, there's nothing new in the vanilla-AHK struct-handling front? Actually, if I hold out long enough, I'll just use IronAHK & (I'm guessing) that should have all the struct-handling I need!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Bing [Bot], LazyMan, rbrtryn and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group