Jump to content

Recommended Posts

Posted

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.

TIA

Posted

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())
Else
  MsgBox(0, "", "OK" & @CRLF & _
  "From Buffer:  " & $return[2])
EndIf

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",_
                        "int",$FORMAT_MESSAGE_FROM_SYSTEM,_
                        "ptr",0,_
                        "int",$ret[0],_
                        "int",0,_
                        "ptr",DllStructGetPtr($p),_
                        "int",4096,_
                        "ptr",0)
    $s    = DllStructGetData($p,1)
    $p = 0
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s
EndFunc

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
×
×
  • Create New...