Link to home
Start Free TrialLog in
Avatar of rng
rng

asked on

GetSystemDirectory .

Here is a portion of my program.

'Declarations
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Dim l as long, strDir as string
l = GetSystemDirectory(strDir, 20)


I want to use GetSystemDirectory to find the path to the system directory. However, it return 0 (0 means function call fail). I don't know why ? Is my program code wrong ?
Does any other function do the same?? I want to find a path to the system directory.
Please help.

Regards,

Raymond
Avatar of Ruchi
Ruchi

This should solve your problem...
http://www.ozemail.com.au/~measlea/api/sysdir.htm
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Private Sub Command1_Click()
    Dim lRet As Long
    Dim sBuffer As String
    sBuffer = String(260, Chr(0))
    lRet = GetSystemDirectory(sBuffer, 260)
    sBuffer = Left(sBuffer, lRet)
    Debug.Print sBuffer
End Sub
From http://members.tripod.com/cuinl/Tips/systemdir.htm

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert this code to the module :

Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long

'Insert this code to your form:

Private Sub Form_Load()
Dim S As String
S = String(80, 0)
Call GetSystemDirectory(S, 80)
UserName = Left(S, InStr(S, Chr(0)) - 1)
MsgBox (S)
End Sub
Avatar of rng

ASKER

Thank you very much.