Jump to content

DllCall, error in my syntax?


Recommended Posts

Hi, just for testing purposes I tried to make a script using the GetAllUsersProfileDirectory function.

Problem is, that the script crashes when I try to run it(something wrong in the DllCall..)

This is the code I have so far:

$lpProfileDir = DllStructCreate("char[255]")

If @error Then 
    MsgBox(0, "Error", @error)
    Exit
EndIf

$a = DllCall("Userenv.dll", "int", "GetAllUsersProfileDirectory", "ptr", DllStructGetPtr($lpProfileDir), "dword", 255)

If @error Then 
    MsgBox(0, "Error", @error)
    Exit
EndIf

MsgBox(0, "AllUsers Dir", DllStructGetData($lpProfileDir, 0))

Documentation about the function can be found here:

http://msdn2.microsoft.com/en-us/library/bb507783.aspx

I hope someone experienced in using DllCall could respond to this, as I also have some other questions regarding how c++ structures and calling syntax(es) converts to AutoIt's DllCall usage. :rolleyes:

Link to comment
Share on other sites

you allmost had it

$lpProfileDir = DllStructCreate("char[256]") ; +1 for the terminating null

If @error Then
    MsgBox(0, "Error", @error)
    Exit
EndIf

; LPDWORD -> long_ptr
$a = DllCall("Userenv.dll", "int", "GetAllUsersProfileDirectory", "ptr", DllStructGetPtr($lpProfileDir), "long_ptr", 255)

If @error Then
    MsgBox(0, "Error", @error)
    Exit
EndIf

; Element index starts with 1
MsgBox(0, "AllUsers Dir", DllStructGetData($lpProfileDir, 1))
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

I forgot to say that the script crashed for some weird reason :S

"+1 for the terminating null"

I suspected that, but I wasn't really sure.

"LPDWORD -> long_ptr"

Yes, I thought the LP stood for "long pointer", but when I tried it, the script still crashed... but I only tested it on the first parameter (whops :rambo:)

But I don't get how the "easier" way works, the documentation doesn't say that it will return the value as it's return value if the first parameter is NULL :S Care to explain to me?

"Element index starts with 1"

whops, careless misstake on my part, but the script was still crashing because of the DllCall... :S

I'm a little confused, anyways thanks for your help in sorting those problems out for me. :rolleyes:

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