Announcement

Collapse
No announcement yet.

Easy question

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

  • Easy question

    I could probably figure this out at the cost of a couple of reboots...


    I want to make an application that will simply init my DLL and then sit and spin and Do *NOTHING*

    The DLL Will do the work (Thanks Wyman! I went to town on that DLL!)...


    Anyway, the app has to be invisible, not be in the system tray, not be in the task manager (Windows only, can't avoid NT)..

    Can't even see the dialog to create it invisible, has to be invisible from time one...

    Thanks,

    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
    Originally posted by Scott Turchin:


    Anyway, the app has to be invisible, not be in the system tray, not be in the task manager (Windows only, can't avoid NT)..

    Can't even see the dialog to create it invisible, has to be invisible from time one...

    One trick is to create the window offscreen, as below:

    Code:
    DIM xpos AS LONG 
    DIM ypos AS LONG               
    
    Dialog get loc WinHdl To xpos, ypos   'get window location
    DIALOG SET LOC WinHdl, -100, -100     'move it off screen
    DIALOG SHOW MODELESS hDlg, CALL DlgProc 
    DIALOG SHOW STATE WinHdl, %SW_HIDE    'hide window
    Dialog set loc WinHdl, xpos, ypos     'move back on screen
    As for the TaskManager, I know there is a way to do this but I can't recall it off hand.



    ------------------
    Peter Amick
    Baybuild Solutions
    Peter Amick
    Baybuild Solutions

    Comment


    • #3
      Task manager is easy, take the steps to put it in the system tray, but DON'T...
      It deletes it from the task bar etc, and walah, invisible...I'll post the code when I get it done...

      This may work, I'll letcha know

      Thanks

      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

      Comment


      • #4
        My $0.02...

        Creating a Window "off the screen" can be problematic if multiple desktops (monitors) are in use... you could inadvertantly create a "hidden" window that appears on another monitor...

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

        Comment


        • #5
          I am pretty sure that it is possible, because I have had a DLL running for 'hours' after the program that started it was terminated.
          I did this by accident, but the DLL was supposed to send periodic updates to the main program on it's status and respond to 'commands' from the main program.
          I think you have to use the SDK/API version of DoEvents and the apiSleep function.
          Dave Navarro posted these routines -or- they were included with PB/DLL 5.0 samples.

          Joe Murphy

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

          Comment


          • #6
            Hate to drag this up, but on Win98 that dialog is visible in the task bar, whether I do a dialog show state hdLg Dialog Show State hDlg,%SW_HIDE or not....


            There has to be a way to create a window invisible doesn't there? or not create one at all?

            Part of me is thinking of the PB/CC solution and hex editing the final executable so it's invisble...


            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

            Comment


            • #7
              Try making the dialog a tool-window, since they do not show in the taskbar... Use the extended style %WS_EX_TOOLWINDOW.



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

              Comment


              • #8
                Lance,
                Good point. I use this method, though, in my Net Connector program and haven't had any complaints so far. Don't know how many two-monitor systems there are out there, though.

                Scott,
                Haven't specifically checked Win98 lately, but the method I mentioned works fine on 95 and NT (doesn't show in the task bar). The program does have a tray icon, though, and that may have some effect.
                Doing a quick run through POFFS, I see that you posted a similar question back in July. One of the respondents mentioned creating the window with the WS_ES_TOOLWINDOW extended style, and someone else suggested setting the window size to 0,0. Haven't tried either of these.




                ------------------
                Peter Amick
                Baybuild Solutions
                Peter Amick
                Baybuild Solutions

                Comment


                • #9
                  Still a no go Wonder why..

                  Code:
                  Function WinMain (ByVal hInstance     As Long, _
                                    ByVal hPrevInstance As Long, _
                                    lpCmdLine           As Asciiz Ptr, _
                                    ByVal iCmdShow      As Long) As Long
                  
                  Local szClassName As Asciiz * 80
                  szClassName = "SPYDER"
                  
                  If IsTrue App_PrevInstance(szClassName) Then
                      Exit Function
                  Else
                      hMutex = CreateMutex(ByVal %Null, 0, szClassName)
                  End If
                  
                  
                  Dialog New 0,"" ,10, 10,30,30,, %WS_EX_TOOLWINDOW   To hDlg
                  'Dialog Set Loc hDlg, -100, -100
                  Dialog Show Modal hDlg Call DialogProc To g_Result
                  CloseHandle hMutex
                  End Function  ' WinMain
                  
                  '------------------------------------------------------------------------------------------
                  CallBack Function DialogProc() As Long
                    Select Case CbMsg
                      Case %WM_CREATE
                      Case %WM_DESTROY
                      Case %WM_INITDIALOG
                          InitializeCCSDLL
                          Dialog Show State hDlg,%SW_HIDE
                    End Select
                  End Function
                  ------------------
                  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


                  • #10
                    Some "normal" dialog styles (ie, %WS_CHILD) are mutually exclusive with the %WS_EX_TOOLWINDOW style. Try something like this (off the top of my head, so E&OE please!)
                    Code:
                    DIALOG NEW hWndParent, "title", x, y, xx, yy, _
                      %WS_SYSMENU OR %WS_THICKFRAME OR %DS_MODALFRAME, _
                      %WS_EX_TOOLWINDOW TO hDlg

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

                    Comment


                    • #11
                      Scott,

                      If you have MSDN (or use MSDN online) search for Matt Pietrek's article on "injecting a DLL into another process".

                      It shows you how to inject a DLL into the "desktop" process.

                      --Dave

                      ------------------
                      Home of the BASIC Gurus
                      www.basicguru.com
                      Home of the BASIC Gurus
                      www.basicguru.com

                      Comment


                      • #12
                        im a bit confused by this thread...
                        my understanding was that DLL's can only run and do their thing while the process that loaded it is running... ? so if myprog.exe loads mydll.dll , and I kill myprog.exe using a standard call to TerminateProcess, surely mydll.dll will also be killed ? - even when the DLL has been "injected" - re: Pietrek, it should be unloaded by the OS when the calling process dies
                        so isn't what Scott wants to do - dare i say it - "impossible" ?
                        Thanks,
                        Wayne



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

                        Comment


                        • #13
                          No. When the app closes, each loaded/referenced DLLs' instance count is reduced by one, and the DLLs will only be unloaded from memory once their reference count reaches zero.

                          I'm just guessing, but the article you refer to is probably talking about a DLL within the "scope" of a single process (just to keep the explanation simple, and since that level of detail is in the realm of advanced programming ).

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

                          Comment


                          • #14
                            Not to mention, I have ONE dialog box, one instance, and the only time my app will get sut down is when the guy shuts his computer down....


                            But isn't it also possible to use a global count integer, add each instance and if it goes over one exit the DLL???

                            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

                            Comment


                            • #15
                              OK I give up on creating an invisible window, I didn't realize it would be such a pain in the ASTERISK...

                              What about a timer function, with no dialog, just SOMETHING to get this DLL initialized and hold itself in memory, the EXE does nothing....just inits the DLL and it does all the work...

                              There has got to be an easy way to do this without the user knowing a dialog is there..

                              What about a modeless dialog box? Does it require a modal dialog box??


                              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

                              Comment


                              • #16
                                Global variables are only global within a single instance of the module that they are defined.

                                That is, global variables in a DLL are not visible to the EXE that loads the DLL, and vice-versa (although they share the same process address space, they can be made visible py passing a pointer back and forwards). However, they are _completely_ isolated from each instance of a DLL (or process), since each process has it's own address space, stack, etc.

                                So how do you pass data between instances of a DLL or application? Use Inter-Process Communication (IPC) techniques. Check out WM_COPYDATA in WIN32.HLP for one of the easiest techniques, and search www.msdn.microsoft.com for IPC for information on other IPC techniques.


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

                                Comment


                                • #17
                                  Hi Again Scott,
                                  Do you need to make a dialog at all? The only thing the EXE is
                                  doing is holding your hook DLL in memory, isn't it? Maybe I'm missing
                                  something? In my EXE I just had a LoadLibrary call in PBMain
                                  and a Do Loop with sleep 65000 or something. A WaitForSingleObject
                                  with an infinite (-1) timeout would probly be cleaner, though.
                                  Can't you use RegisterServiceProcess(GetCurrentProcessID, Action&)
                                  to hide your EXE from the tasklist?
                                  Good Luck!!


                                  ------------------
                                  [email protected]

                                  [This message has been edited by Wyman A Belts (edited December 12, 2000).]

                                  Comment


                                  • #18
                                    Code:
                                    Scott--
                                       
                                    I'm puzzled by your references to hiding a window.  Why create one at 
                                    all?  Have a look at the following. (The ShowMsg function is included 
                                    just to simplify message display for either PBDLL and PBCC.)
                                       
                                    Greg
                                       
                                    '---------------------------------------------------------------------
                                    '-- Your DLL
                                    '---------------------------------------------------------------------
                                    #COMPILE DLL "STEALTH.DLL"
                                    #REGISTER NONE
                                    #DIM ALL
                                       
                                    '============
                                    DEFLNG A-Z
                                       
                                    #INCLUDE "WIN32API.INC"
                                    GLOBAL hINST&, DLLNAME$
                                    DECLARE SUB ShowMsg(Msg$)
                                       
                                    '====================
                                    FUNCTION DllMain&(BYVAL hInstance&, _
                                                      BYVAL Reason&, _
                                                      BYVAL Reserved&) EXPORT
                                    hINST& = hInstance&
                                    select case Reason&
                                       case %DLL_PROCESS_ATTACH
                                          LOCAL ztmp AS ASCIIZ * %MAX_PATH
                                          '-- Retrieve DLL's name for ShowMsg()
                                          if GetModuleFileName(hINST&, ztmp, %MAX_PATH-1) then
                                             DLLNAME$ = ztmp
                                          else
                                             DLLNAME$ = "This DLL"
                                          end if
                                          function = 1 : exit function
                                       case %DLL_PROCESS_DETACH
                                          ShowMsg "%DLL_PROCESS_DETACH" + str$(Reason&)
                                          function = 1 : exit function
                                    end select
                                    END FUNCTION
                                       
                                    '===========================
                                    SUB ShowMsg(Msg$)
                                    '-- MessageBox function wrapper
                                    MessageBox 0, byval strptr(Msg$), byval strptr(DLLNAME$), %mb_TASKMODAL
                                    END SUB
                                          
                                       
                                    '---------------------------------------------------------------------
                                    '-- EXE prop for DLL
                                    '---------------------------------------------------------------------
                                    #COMPILE EXE "STEALTH.EXE"
                                    #REGISTER NONE
                                    #DIM ALL
                                       
                                    '============
                                    DEFLNG A-Z
                                    #INCLUDE "WIN32API.INC"
                                       
                                    DECLARE FUNCTION HideProcess&()
                                    DECLARE SUB ShowMsg(Msg$)
                                    GLOBAL EXENAME$
                                       
                                    '====================
                                    FUNCTION WinMain&(BYVAL CurInst&, _
                                                      BYVAL PrvInst&, _
                                                      CmdLine AS ASCIIZ PTR, _
                                                      BYVAL CmdShow&) EXPORT
                                    LOCAL t$, dllname$, ztmp AS ASCIIZ * %MAX_PATH
                                       
                                    '-- Retrieve EXE's name for ShowMsg()
                                    if GetModuleFileName(CurInst, ztmp, %MAX_PATH-1) then
                                       EXENAME$ = ztmp
                                    else
                                       EXENAME$ = "This EXE"
                                    end if
                                       
                                    dllname$ = ucase$(rtrim$(EXENAME$, "EXE") + "DLL")
                                    if LoadLibrary(byval strptr(dllname$)) = 0 then
                                       ShowMsg "Cannot load required DLL: " + $CR + dllname$
                                       goto ExitWinMain
                                    end if
                                       
                                    if HideProcess& then t$ = " hidden"
                                    ShowMsg "Starting" + t$
                                       
                                    '-- For demo purposes, cutoff in 10 seconds
                                    WaitForSingleObject GetCurrentThread, 10000
                                    ''WaitForSingleObject GetCurrentThread, %INFINITE
                                       
                                    ShowMsg "Ending"
                                       
                                    '============
                                    ExitWinMain:
                                    END FUNCTION
                                       
                                    %RSP_SIMPLE_SERVICE = 1 : %RSP_UNREGISTER_SERVICE = 0
                                    '====================
                                    FUNCTION HideProcess&()
                                    '-- Works under Win 9x only
                                    '   Does nothing if OS function is unavailable
                                    '   Returns %TRUE on success
                                    LOCAL hlib&, pRegisterServiceProcess AS DWORD PTR
                                    hlib& = LoadLibrary("KERNEL32.DLL")
                                    if hlib& then
                                       pRegisterServiceProcess = GetProcAddress(hlib&, "RegisterServiceProcess")
                                       if pRegisterServiceProcess then
                                          call dword pRegisterServiceProcess CDECL _
                                                    (BYVAL GetCurrentProcessId, _
                                                     BYVAL %RSP_SIMPLE_SERVICE)
                                          function = %TRUE
                                       end if
                                       call FreeLibrary(hlib&)
                                    end if
                                    END FUNCTION
                                       
                                    '===========================
                                    SUB ShowMsg(Msg$)
                                    '-- MessageBox function wrapper
                                    MessageBox 0, byval strptr(Msg$), byval strptr(EXENAME$), %mb_TASKMODAL
                                    END SUB

                                    [This message has been edited by Greg Turgeon (edited December 12, 2000).]

                                    Comment


                                    • #19
                                      You all are right on the money, the exe just calls this function in the DLL


                                      Function InitCCSDLL
                                      Local Dummy as long
                                      Dummy = %FALSE
                                      End Function


                                      By doing that the DLL loads and begins operation and life is good

                                      At that point in time I'm happy, so I could do a WaitForSingleObject, my only concern would be it locking up the machine hehe, otherwise that might work fine, the other one up there looks confusing but promising so I'll take a gander at it...

                                      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

                                      Comment


                                      • #20
                                        Lance, if I read you correctly (and I'm not passing anything between DLL and EXE) I can't use a counter in the DLL either?

                                        If I had to do something like that, and I forget how that topic came into this, but lets say I want to count instances of the DLL inside the DLL, can I use a gNumberofInstances variable and validate it does nto go over 1??


                                        The WaitforSingleObject works fine, definitely does the job nicely...


                                        Now the issue goes to the count, for some reason it wants to end the DLL mid stream, and there's no code to do that...

                                        (It sends an email when complete, I have debug MSGBOX's in it for now and it sends 3 emails per run)..

                                        Very strange, but its' almost done....


                                        Thanks guys

                                        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

                                        Comment

                                        Working...
                                        X