I want to know on which location my application is running and I don't want to use application.path , i want is there any API that can tell the location ?
Printable View
I want to know on which location my application is running and I don't want to use application.path , i want is there any API that can tell the location ?
Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Paint()
Dim sSave As String
'create a buffer
sSave = String(255, 0)
'retrieve the current directory
GetCurrentDirectory 255, sSave
MsgBox sSave
End Sub
What's with the Form_Paint()
event.
Thats just an example.
You can also take use of "form_load" or " command1_click" instead of "form_paint".
What's wrong with App.Path??Quote:
Originally posted by manishmenghani
I want to know on which location my application is running and I don't want to use application.path , i want is there any API that can tell the location ?
Using GetCurrentDirectory is not the same as using App.Path.
App.Path always returns the directory your exe is located in.
The GetCurrentDirectory API will return the current directory for the program.
If you make a shortcut to your exe file and set the "Start in" directory to be something other than the directory your program is in, App.Path and GetCurrentDirectory will have different results when you run your program from the shortcut.
By the way, you can use the CurDir function. It will do the same thing as the GetCurrentDirectory API. You might want to do that anyway, because He-M@n forgot to include code to get rid of the nulls at the end of the string returned by GetCurrentDirectory.