15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Writing SERVICES with MFC, Can it be Done, Maybe?

wayne.dengel@octel.com
Monday, July 29, 1996

     Environment: VC4.0 and NT4.0 Beta2
     
     Hello,
     
     I have an app that uses a class derived from CWinThread.  I want to 
     run this class as an MFC Service.  Heres what I did.
     
     1: Created an MFC Dialog App.
     2: Stripped the Dialog from the App.
     3: In InitInstance in theApp I created a CWnd (To satisfy CWinThread) 
     4: In this CWnd, I am creating and running my CWinThread Class
     5: After this, still in init, I am starting this app as a service.
     
     Is this possible?
     
     I created the CWnd in the app to satisfy CWinThread, because, I think 
     that CWinThread need a parent Wnd to start.  Is this TRUE?
     
     Is there any other way to do this and make it work.  I had it running 
     for a while, but is wasn't right.
     
     Thanks for any advice.
     
     Wayne
     
     
     
     PS Here is an snippet from the code.  I know you need more but, but I 
     don't want to take up too much space.
     
     BOOL CIVRServiceApp::InitInstance()
     {  OSVERSIONINFO version;                  //OS Version info struct
        pWnd=(CMainWnd *) new CMainWnd;         // Create MAIN wnd
     
        Enable3dControls();             
     
        pWnd->Create(NULL,"Ocapi Frame");       //OBJECT Wnd 
        m_pMainWnd=pWnd;      
     
        version.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);                  
        GetVersionEx(&version);                 // Get the OS Type & Info
        if(version.dwPlatformId==VER_PLATFORM_WIN32_NT)
                b_NT=TRUE;
       else
                b_NT=FALSE;
     
        if(b_NT){
                dispatchTable[0]=new SERVICE_TABLE_ENTRY;       
                dispatchTable[1]=new SERVICE_TABLE_ENTRY;                   
                dispatchTable[0]->lpServiceName=TEXT(SZSERVICENAME); 
                dispatchTable[0]->lpServiceProc=service_main; 
                dispatchTable[1]->lpServiceName=NULL; 
                dispatchTable[1]->lpServiceProc=NULL;
                CString str;
                str.Format("%s",m_lpCmdLine);
                if(str.Find("install")>-1){
                        CmdInstallService();     // Call INSTALL routine 
                        return FALSE;            // Tell APP we are done
                }else if(str.Find("remove")>-1){ 
                        CmdRemoveService();      // Call REMOVE routine 
                        return FALSE;            // Tell APP we are done
                }
        }
     
        if(!StartServiceCtrlDispatcher((*dispatchTable))){
                AddToMessageLog(TEXT("StartService FAILED.")); return       
                FALSE;
        }
     
        return TRUE;
     }
     
     Unfortunatly, the StartServiceCtrlDispatcher, does NOT return until 
     the Control thread is DONE.  So I wanted to return but NOT end the 
     thread.  Any Ideas
     



Luca Orlandi -- Luca.Orlandi@inferentia.it
Friday, August 02, 1996

On luned=EC 29 luglio 1996 17.56, wayne.dengel@octel.com wrote:
>     Environment: VC4.0 and NT4.0 Beta2
Take a look at Sam Blackburn's WFC32 classes =
http://ourworld.compuserve.com/homepages/Sam_Blackburn/wfc.htm ther's a =
CService class.




| Вернуться в корень Архива |