Announcement

Collapse
No announcement yet.

Which API to find exe path

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Robert Floyd
    replied
    Thanks much,
    Bob

    Leave a comment:


  • Kev Peel
    replied
    Hi Bob,

    JFYI: Although CURDIR$ will return the current directory, the directory it returns is not necessarily the actual program path (ie. the current folder can be changed if the EXE is run from a different folder or shortcut). Whereas GetModuleFileName will always return your EXE's path.

    Leave a comment:


  • Robert Floyd
    replied
    Thanks Mel,

    I've got the other code running. & I'm not sure whether CURDIR$ will work, but I'll give it a test as it is quite simple to use.

    Best Regards,
    Bob

    Leave a comment:


  • Robert Floyd
    replied
    Thanks Fred & Kev,

    This is exactly what I was after - I used code from both of you. Also, the use of INSTR to search from right to left was welcome news to me. I don't think that's in VB.

    Best Regards,
    Bob Floyd

    Leave a comment:


  • Mel Bishop
    replied
    Well, if I'm reading your query right, CURDIR$ should do the trick.

    Leave a comment:


  • Kev Peel
    replied
    You'd want the file name stripped, so it would be:

    Code:
      szBuffer = Left$(szBuffer, Instr(-1, szBuffer, ANY "\/")-1)
    Also remember to #include "win32api.inc" in your code, if you haven't already.

    Leave a comment:


  • Fred Harris
    replied
    Here's a console compiler example...

    Code:
    #Compile Exe
    #Dim All
    #Include "Win32Api.inc"
    
    Function PBMain() As Long
      Local szBuffer As Asciiz*256
      Local dwSize As Dword
      
      dwSize=256
      GetModuleFileName(%NULL,szBuffer,dwSize)
      Print "Path = "szBuffer
      Waitkey$
    
      PBMain=0
    End Function

    Leave a comment:


  • Fred Harris
    replied
    GetModuleFileName

    The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.

    Windows 95: The GetModuleFilename function will return long filenames when an application's version number is greater than or equal to 4.00 and the long filename is available. Otherwise, it returns only 8.3 format filenames.

    DWORD GetModuleFileName
    (
    HMODULE hModule, // handle to module to find filename for
    LPTSTR lpFilename, // pointer to buffer to receive module path
    DWORD nSize // size of buffer, in characters
    );

    Parameters

    hModule

    Handle to the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process.

    lpFilename

    Pointer to a buffer that is filled in with the path and filename of the given module.

    nSize

    Specifies the length, in characters, of the lpFilename buffer. If the length of the path and filename exceeds this limit, the string is truncated.

    Return Values

    If the function succeeds, the return value is the length, in characters, of the string copied to the buffer.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    Remarks
    If a module is loaded in two processes, its module filename in one process may differ in case from its module filename in the other process.

    Leave a comment:


  • Robert Floyd
    started a topic Which API to find exe path

    Which API to find exe path

    In VB, I am used to using App.Path to get the path to my currently executing VB exe file. I am having trouble finding an API call to do the same for my PB8 exe file. Any suggestions would be welcome.

    Thanks,
    Bob
Working...
X
😀
🥰
🤢
😎
😡
👍
👎