Announcement

Collapse
No announcement yet.

Getting argv[0] in PBCC

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

  • Adam J. Drake
    replied
    Try this:

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    
    DECLARE FUNCTION AppPath() AS STRING
    
    FUNCTION PBMAIN () AS LONG
    
        PRINT AppPath()
        WAITKEY$
    
    END FUNCTION
    
    FUNCTION AppPath() AS STRING
        
        LOCAL sRet          AS STRING
        LOCAL lpFileName    AS ASCIIZ * %MAX_PATH
        LOCAL nSize         AS DWORD
        LOCAL hModule       AS DWORD
        LOCAL dwLen         AS DWORD
        
        hModule = GetModuleHandle(BYVAL %NULL)
        nSize = %MAX_PATH
        dwLen = GetModuleFileName(hModule, lpFileName, nSize)
        
        IF dwLen <> 0 THEN
            sRet = MID$(lpFileName, 1, INSTR(-1, lpFileName, "\"))
        END IF
        
        FUNCTION = sRet
        
    END FUNCTION

    Leave a comment:


  • Erich Schulman
    replied
    The API looks to be the more reliable way for my purposes.

    I already know my program will be called by a .bat which will be called by Windows Scheduler. The .exe would be called from an absolute path to be sure it is found without having to add its directory to the PATH. Therefore, CURDIR$ will not necessarily return where the .exe is located. I want to guarantee that my log files will be in the same place as the .exe without assuming anything about where the user might have put the .exe.

    Leave a comment:


  • Fred Harris
    replied
    Curdir$ in PowerBASIC

    or in Api


    Code:
    GetCurrentDirectory
    The GetCurrentDirectory function retrieves the current directory for the current process. 
    
    DWORD GetCurrentDirectory(
      DWORD nBufferLength,  // size, in characters, of directory buffer
      LPTSTR lpBuffer       // pointer to buffer for current directory
    );
     
    Parameters
    
    nBufferLength 
    
    Specifies the length, in characters, of the buffer for the current directory string. The buffer length must include room for a terminating null character. 
    
    lpBuffer
     
    Pointer to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory. 
    
    Return Values
    
    If the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character. 
    
    If the function fails, the return value is zero. To get extended error information, call GetLastError. 
    
    If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character.

    Leave a comment:


  • Erich Schulman
    started a topic Getting argv[0] in PBCC

    Getting argv[0] in PBCC

    I actually don't even need the .exe's name, just the full path of the directory that the .exe is in. How do I get this in PBCC4.03?
Working...
X
😀
🥰
🤢
😎
😡
👍
👎