Jump to content
Sign in to follow this  

DLLCall help needed.

Recommended Posts


Ok, I'm not a programmer/coder, so no laughing. :P

I'm trying to call the "LSGetVariableEx" function in the lsapi.dll for Litestep. The example use of the function is:

BOOL LSGetVariableEx(
    LPCSTR pszKeyName,
    LPSTR pszBuffer,
    UINT cbBuffer

The variable I'm trying to get is "ConfigDir." The expected return is the path to the config directory, something like "c:\litestep\themes\themename\config."

I've tried tons of different things, but I'm confused about what to do for the "types" in the DLLCall, and I'm sure I'm messing up the DllStructCreate. This is the last thing I tried:

$buffer = DllStructCreate("byte")

$error = DllCall("c:\litestep\lsapi.dll", "none", "LSGetVariableEx", _
"char", "ConfigDir", "char", $buffer, "ptr", DllStructGetPtr($buffer))

MsgBox(0, "", "Error:  " & $error & @CRLF & _
"From Buffer:  " & DllStructGetData($buffer, 1))

Both values in my msgbox are zero with the above.

If anyone could give me suggestions to try, it'd be appreciated.


Share this post

Link to post
Share on other sites

See this:

DllCall, Syntax notes and API list

And your code should be something like this:

(There is also robust error checking for better testing)

$return = DllCall("c:\litestep\lsapi.dll", "int", "LSGetVariableEx", _
"str", "ConfigDir", "str", "", "int", 255)

If @error Then
  MsgBox(0, "", "Error:  " & @error & @CRLF & _
  "Error description:  " & _GetLastErrorMessage())
  MsgBox(0, "", "OK" & @CRLF & _
  "From Buffer:  " & $return[2])

Func _GetLastErrorMessage($DisplayMsgBox="")
    Local $ret,$s
    Local $p    = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM        = 0x00001000

    If @error Then Return ""

    $ret    = DllCall("Kernel32.dll","int","GetLastError")

    $ret    = DllCall("kernel32.dll","int","FormatMessage",_
    $s    = DllStructGetData($p,1)
    $p = 0
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s

Share this post

Link to post
Share on other sites

Great link, thank you.

Unfortunately, the solution you provided didn't work for me. I'll keep playing with it.

There was no error, but $return[2] was empty. :P

Edited by xcal

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