Announcement

Collapse
No announcement yet.

Is a running PBCC executable aware of its own name?

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

    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
    Christopher P. Becker
    signal engineer in the defense industry
    Abu Dhabi, United Arab Emirates

    #2
    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
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    Comment


      #3
      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?
      Christopher P. Becker
      signal engineer in the defense industry
      Abu Dhabi, United Arab Emirates

      Comment


        #4
        Code:
            [B]c = SIZEOF(b)[/B]
            t = GetModuleFilename(hModule, b, c)
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


          #5
          Works! Thanks!
          Christopher P. Becker
          signal engineer in the defense industry
          Abu Dhabi, United Arab Emirates

          Comment


            #6
            >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
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


              #7
              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
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎