Announcement

Collapse
No announcement yet.

Run from IDE?

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

  • Run from IDE?

    Is there an IF statement (#IF) that would tell an app whether or not it had been run from within the IDE?

    Boy that would be helpful, my Evaluation dialog box is annoying me and I don't want ot REM it out just for testing....but to bypass it from within the IDE would be great..


    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Launching your program from the IDE is no different from launching it
    any other way. However, I imagine you could have your program check
    the titles of all the running applications, and react accordingly if
    it sees one of the PowerBASIC IDEs-- for development purposes, anyway.


    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Does the IDE create a mutex by chance? That's the most reliable method I've found yet...
      I have process code now but that's a lot of overhead just for debug purposes..


      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        This works, but how ungainly and ugly it is hehe.


        Code:
        szDebug = "PowerBASIC 32-bit DLL Compiler for Windows - [H:\PBDLL\PYTHON\Eval\python32.bas]"
        If FindWindow("",szDebug) Then GoTo CONTINUE
        '=-===============<EVAL COPY ONLY>==============
        Local ExpMessage As String
        ExpMessage = "This EVALUATION Copy of " & g_szMine & " has expired"
        If IsTrue CheckIfEvaluationExpired Then
           EvalMessage 0,g_szMine,ExpMessage
           Exit Function
        End If
        ExpMessage = "This is an evaluation copy of " & g_szMine & " and will expire in 10 days."
        EvalMessage 0,g_szMine,ExpMessage
        '=-===============<EVAL COPY ONLY>==============
        CONTINUE:
        ------------------
        Scott
        mailto:[email protected][email protected]</A>
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          A Mutex is an excellent idea, Scott! I'll pass that along to R&D.

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Following works fine on my PC (Win2000).
            Idea is to test WriteTime (here: if created more than 5 sec ago - means not from IDE)
            Code:
               #Compile Exe
               #Register None
               #Dim All
               #Include "win32Api.Inc"
               
               Function RunFromIde As Long
                  Dim lpFileName As Asciiz * %MAX_PATH, hFile As Long, q(2) As Quad, st As SYSTEMTIME
                  GetModuleFileName ByVal GetModuleHandle(ByVal 0&), lpFileName, SizeOf(lpFileName)
                  hFile = CreateFile(lpFileName, %GENERIC_READ, _
                     %FILE_SHARE_READ, ByVal %NULL, %OPEN_EXISTING, %FILE_ATTRIBUTE_NORMAL, ByVal %NULL)
                  GetFileTime hFile, ByVal VarPtr(q(0)), ByVal VarPtr(q(1)), ByVal VarPtr(q(2))
                  CloseHandle hFile
                  GetSystemTime st: SystemTimeToFileTime st, ByVal VarPtr(q(0))      
                  If (q(0) - q(2)) / 10000000 < 5 Then Function = 1
               End Function
               
               Function PbMain
                  If RunFromIde Then MsgBox "From IDE" Else MsgBox "Not from IDE"
               End Function
            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              > A Mutex is an excellent idea,

              But a mutex would only tell your program whether or not the IDE was currently running, not whether or not the program was launched by the IDE.

              How about an ENVIRON string? When the IDE launches an app it could add a string like PB_IDE=Y to the envorinment that was passed to the app. The app would be the only process that could see the string.

              -- Eric


              ------------------
              Perfect Sync: Perfect Sync Development Tools
              Email: mailto:[email protected][email protected]</A>

              [This message has been edited by Eric Pearson (edited February 16, 2001).]
              "Not my circus, not my monkeys."

              Comment


              • #8
                True, and both ideas are very good...
                But, if a Mutex is there then PB is running, and I VERY seldom launch an app with the IDE running without just using the IDE..

                Sometimes I do, so FindWindow, Mutex, and an Environ string would all be great things..


                Scott


                ------------------
                Scott
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9

                  Scott,

                  Personally I think the 'FindWindow' method is a little 'clunky'

                  What about the IDE using SetProp on GetDesktopWindow with the application's EXE name ?!?

                  Failing that, create a hidden window, called "PBIDE" or something with the property set.

                  Then, if the property is set to non-zero your program is being run from the IDE.

                  Comments?

                  ------------------
                  Kev G Peel
                  KGP Software, Bridgwater, UK.
                  http://www.kgpsoftware.com
                  kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                  Comment


                  • #10
                    Personally, the Mutex would be quite suitable. I avoid using enviroment strings where possible, but that idea is also quite plausable.

                    Hidden Windows? SetProp? To me, they both seem unnecessarily complicated for a simple "IsIDE" operation...

                    We'll have to see if/what R&D dream up...

                    ------------------
                    Lance
                    PowerBASIC Support
                    mailto:[email protected][email protected]</A>
                    Lance
                    mailto:[email protected]

                    Comment


                    • #11
                      The mutex is simply the most reliable and stable and easiest method of doing it!


                      Scott

                      ------------------
                      Scott
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #12
                        Mutex? Doesn't that assume that only one copy of the IDE may run at a
                        time, or am I missing something here? Eric's suggestion of an environment
                        string makes sense to me.

                        Anyway, it's a useful notion, and I'll pop it on the list.

                        ------------------
                        Tom Hanlin
                        PowerBASIC Staff

                        Comment


                        • #13
                          If Internally PB did this we'd be just fine We'd have to do the same if we wanted multi-copies open tho..

                          Code:
                          For x = 1 to 20 '20 copies open?
                            if App_PrevInstance(lpClassname) Then
                               lpClassname = lpClassname & Str$(x)
                            Else 
                               g_hMutex = CreateMutex(ByVal %Null, 0, lpclassName)
                            End if
                          Next
                          
                          Function App_PrevInstance(lpclassName As Asciiz) As Long
                          Local hMutex As Long
                          hMutex = CreateMutex(ByVal %Null, 0, lpclassName)
                          If hMutex = 0 Then Exit Function ' Error in Mutex
                          If GetLastError = %ERROR_ALREADY_EXISTS Or FindWindow(lpClassName, "") > 0 Then Function = %TRUE
                          CloseHandle hMutex
                          End Function
                          ------------------
                          Scott
                          Scott Turchin
                          MCSE, MCP+I
                          http://www.tngbbs.com
                          ----------------------
                          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                          Comment


                          • #14
                            It seems to be that a simple way of detecting the presence of the IDE (regardless of the number of copies running) would be a useful tool.

                            Maybe the IDE could create a MUTEX using the application filename.

                            An environment string would be equally useful, but if this could be implemented as an internal (system) variable of the compiler, it would be incredibly simple to use. For example

                            IF PBDLLIDE THEN dosomething.

                            While this could be created with a small wrapper function around a ENVIRON$() or CreateMutex() call, moving such functionality inside the RTL would make life a little easier.

                            One example of this functionality comes to mind: This kind of code could be left in the "distributable" file, and by simply setting an environment string (or a small app to create the Mutex), the application could start it's own data logging code, aiding the task of debugging an app in situ.

                            Think of it as another tool to help the application developer debug applications in the field without the need to stop and start the app.

                            My 2% of 1$.



                            ------------------
                            Lance
                            PowerBASIC Support
                            mailto:[email protected][email protected]</A>
                            Lance
                            mailto:[email protected]

                            Comment


                            • #15
                              Lance --

                              Are you saying that something like an IDE_Debug_Print functionality might be possible?

                              --
                              Best Regards
                              Peter Scheutz

                              ------------------
                              Best Regards
                              Peter Scheutz

                              Comment


                              • #16
                                Replace PBMAIN with..
                                Code:
                                FUNCTION WinMain (BYVAL hCurInstance  AS LONG, _
                                                  BYVAL hPrevInstance AS LONG, _
                                                  lpszCmdLine         AS ASCIIZ PTR, _
                                                  BYVAL nCmdShow      AS LONG) EXPORT AS LONG
                                Use the IDE menus:

                                (R)un (C)ommand line = "RUNNING FROM IDE"

                                Put in your code, right in WinMain:

                                Code:
                                   IF @lpszCmdLine = "RUNNING FROM IDE" THEN
                                      RunningFromIDe = %TRUE
                                   ELSE
                                      RunningFromIde = %FALSE
                                   END IF
                                MCM
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  Michael,

                                  Good idea, and you can use COMMAND$ instead of @lpszCmdLine, but
                                  each time you enter the IDE you have to reset the command line.

                                  ------------------

                                  Comment

                                  Working...
                                  X