Announcement

Collapse
No announcement yet.

Is a running PBCC executable aware of its own name?

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

  • Michael Mattias
    replied
    Why? Because I've written a SUB that will be #INCLUDEd into multiple programs, and I want the SUB to know the name of the EXE that's calling it
    This will work as long as the EXE has not been renamed... which of course is perfectly legal.

    It might be better to have the function(s) in this #INCLUDE file accept a parameter which tells it "who is calling me."

    e.g

    Code:
    FUNCTION IncludedFunction (BYVAL %CALLER_NO, other params) AS something 
    
      SELECT CASE AS LONG %CALLER_NO)
          CASE  %CALLER_A 
             do what you do when it's program 'A' making the call
    
          CASE  %CALLER_B 
             do what you do when it's program 'B' making the call
         ....
    Impervious to renaming.

    MCM

    Leave a comment:


  • Michael Mattias
    replied
    >t = GetModuleFilename(hModule, b, c)

    > Works!

    Should be pointed out for lurkers: this works because hModule is never assigned a value and therefore equals zero.

    This would also work with a valid handle to the module

    hModule
    [in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
    Normally what you'd see coded is
    Code:
     hModule = GetModuleHandle (BYVAL %NULL) 
     GetModuleFileName  hModule , szFile, SIZEOF(szFile)
    When %NULL is passed to GetModuleHandle it returns a handle to the current EXE; the same value which is passed as hInstance in the Entry Point function WinMain.

    Note that GetModuleHandle (BYVAL %NULL) returns a handle to the EXE module even if called from a function in a DLL.

    MCM

    Leave a comment:


  • Christopher Becker
    replied
    Works! Thanks!

    Leave a comment:


  • José Roca
    replied
    Code:
        [B]c = SIZEOF(b)[/B]
        t = GetModuleFilename(hModule, b, c)

    Leave a comment:


  • Christopher Becker
    replied
    Code:
    #INCLUDE "win32api.inc"
    FUNCTION PBMAIN () AS LONG
        DIM t AS DWORD
        DIM hModule AS DWORD
        DIM b AS ASCIIZ * 255
        DIM c AS DWORD
        t = GetModuleFilename(hModule, b, c)
        PRINT t, a, b, c
        WAITKEY$
    END FUNCTION
    George, thanks for the tip. It sounds like GetModuleFilename will do what I want. But I can't seem to make it work. The above code just returns a zero, which, according to Microsoft, indicates an error. It seems hModule needs to be zero to work, but nothing is working. Where's my bug?

    Leave a comment:


  • George Bleck
    replied
    GetModuleFilename - Simplest way to do it afaik. Nothing PB intrinsic.

    As for "can be assigned with #COMPILE EXE", what prevents you from renaming it after compile

    Leave a comment:


  • Is a running PBCC executable aware of its own name?

    Suppose I have a working program that was compiled into a file called "FOO.EXE". Will the program, at run time, have access to the name "FOO"? I looked through the metastatements and equates but could not find it. Of course, "FOO" can be assigned with #COMPILE EXE, but I want to Get, not Set.

    Why? Because I've written a SUB that will be #INCLUDEd into multiple programs, and I want the SUB to know the name of the EXE that's calling it.

    I know I can poll the Windows Process IDs to search for it, but that seems like some work (and I hate relying on some Windows mechanism that's not entirely under my control). Wondered if there was an internal PBCC resource I can tap.

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