Home Help Center

A question about service and MFC?

dingding Member
Hi!

I write a program using ICE 1.5.1, in the program I use class Ice::Application , now I want chang it to windows Service program,then i write a class MyService inherited Ice:Service ,but build it ,vc6 report error

service.h(222) : error C2501: 'SERVICE_STATUS_HANDLE' : missing storage-class or type specifiers
service.h(223) : error C2501: 'SERVICE_STATUS' : missing storage-class or type specifiers

if not include afx.h file,build it ok ,but my program used MFC,I must include afx.h file, Why?

Comments

  • dingding Member
    the probelm is resolved!

    in the MyService.h file,include winsvc.h file, build passed!

    thanks!
  • stanley20080628stanley20080628 Member Stanley LeeOrganization: Industrial Technology Research InstituteProject: Robot platform developer with messagebus
    Hi,

    I use service and MFC in staic library with Ice-3.3.1-VC60.
    After I added #include <WINSVC.H> , then come with this compiler error message.
    c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(4296) : error C2065: 'min' : undeclared identifier
            c:\ice-3.3.1-vc60\include\stlport\stl\_alloc.h(349) : while compiling class-template member function 'long __stdcall ATL::CComEnumImpl<struct IEnumConnectionPoints,&struct _GUID const IID_IEnumConnectionPoints,struct IConnectionPoint *,class
     ATL::_CopyInterface<struct IConnectionPoint> >::Next(unsigned long,struct IConnectionPoint ** ,unsigned long *)'
    


    Best wishes,
    Min-hao Lee
    Industrial Technology Research Institute
  • stanley20080628stanley20080628 Member Stanley LeeOrganization: Industrial Technology Research InstituteProject: Robot platform developer with messagebus
    Dear Sir,

    If I don't try to integrated Ice code in my project,it does work.
    My project used PSDK,but Ice use STLPORT at the same time.
    Then I add too->Options->Directories->Include files
    c:\Program Files\Microsoft SDL\include\
    c:\ICE-3.3.1-VC60\Include
    c:\ICE-3.3.1-VC60\Include\stlport

    furthermore,

    c:\ICE-3.3.1-VC60\Include
    c:\ICE-3.3.1-VC60\Include\stlport
    c:\Program Files\Microsoft SDL\include\

    and also,

    c:\ICE-3.3.1-VC60\Include\stlport
    c:\ICE-3.3.1-VC60\Include
    c:\Program Files\Microsoft SDL\include\

    but I got the same error message
    c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(4296) : error C2065: 'min' : undeclared identifier


    Here is my stdafx.h and project setting in VC6.0


    /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I "C:\Ice-3.3.1-VC60\include" /I "C:\Ice-3.3.1-VC60\include\stlport" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_STLP_DEBUG" /D "_USRDLL" /D "_MBCS" /Fp"Debug/MTC.pch" /YX"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c

    // stdafx.h : include file for standard system include files,
    //      or project specific include files that are used frequently,
    //      but are changed infrequently
    
    #if !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_)
    #define AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    
    //
    // For VC6 and STLport
    //
    #if !defined(NDEBUG) && !defined(_STLP_DEBUG)
    #   define _STLP_DEBUG
    #endif
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    
    // Change this to the appropriate value to target Windows 98 and
    // Windows 2000 or later if not using VC6.
    #ifndef _WIN32_WINNT
    #  if defined(_MSC_VER) && _MSC_VER < 1500
    #    define _WIN32_WINNT 0x500
    #  endif
    #endif
    
    #ifndef WINVER
    #  if defined(_MSC_VER) && _MSC_VER > 1300
    #    define WINVER 0x0400
    #  endif
    #endif
    
    #ifndef _WIN32_IE                       // Allow use of features specific to IE 4.0 or later.
    #define _WIN32_IE 0x0400        // Change this to the appropriate value to target IE 5.0 or later.
    #endif
    
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    
    // turns off MFC's hiding of some common and often safely ignored warning messages
    #define _AFX_ALL_WARNINGS
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxtempl.h>
    #include <atlbase.h>
    //You may derive a class from CComModule and use it if you want to override
    //something, but do not change the name of _Module
    
    
    
    // add For ICE
    #include <WINSVC.H>		//ICE&#30340;&#32232;&#35695;&#37679;&#35492;, http://www.cnitblog.com/lizhenbao/archive/2005/11/01/3784.aspx
    #include <Ice/Ice.h>
    // add For ICE
    
    
    
    class CServiceModule : public CComModule
    {
    public:
    	HRESULT RegisterServer(BOOL bRegTypeLib, BOOL bService);
    	HRESULT UnregisterServer();
    	void Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, UINT nServiceNameID, const GUID* plibid = NULL);
        void Start();
    	void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        void Handler(DWORD dwOpcode);
        void Run();
        BOOL IsInstalled();
        BOOL Install();
        BOOL Uninstall();
    	LONG Unlock();
    	void LogEvent(LPCTSTR pszFormat, ...);
        void SetServiceStatus(DWORD dwState);
        void SetupAsLocalServer();
    
    //Implementation
    private:
    	static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        static void WINAPI _Handler(DWORD dwOpcode);
    
    // data members
    public:
        TCHAR m_szServiceName[256];
        SERVICE_STATUS_HANDLE m_hServiceStatus;
        SERVICE_STATUS m_status;
    	DWORD dwThreadID;
    	BOOL m_bService;
    };
    
    extern CServiceModule _Module;
    #include <atlcom.h>
    
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED)
    
    


    Thank you for help!
    Best wishes,
    Min-hao Lee
    Industrial Technology Research Institute
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    I would try to include <atlcom.h> before <Ice/Ice.h>, this will most likely solve this issue (the Ice headers un-define the min macro to avoid conflicts).

    Cheers,
    Benoit.
  • stanley20080628stanley20080628 Member Stanley LeeOrganization: Industrial Technology Research InstituteProject: Robot platform developer with messagebus
    Dear Benoit,

    After I try to include <atlcom.h> before <Ice/Ice.h>,
    vc6 compiling error such as follow.
    Compiling...
    StdAfx.cpp
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(82) : error C2146: syntax error : missing ';' before identifier 'm_hServiceStatus'
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(82) : error C2501: 'SERVICE_STATUS_HANDLE' : missing storage-class or type specifiers
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(82) : error C2501: 'm_hServiceStatus' : missing storage-class or type specifiers
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(83) : error C2146: syntax error : missing ';' before identifier 'm_status'
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(83) : error C2501: 'SERVICE_STATUS' : missing storage-class or type specifiers
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(83) : error C2501: 'm_status' : missing storage-class or type specifiers
    c:\ice-3.3.1-vc60\include\ice\proxy.h(549) : error C2027: use of undefined type 'Object'
            c:\ice-3.3.1-vc60\include\ice\objectf.h(20) : see declaration of 'Object'
    c:\ice-3.3.1-vc60\include\ice\proxy.h(549) : error C2039: 'ice_facet' : is not a member of 'ProxyHandle<class Ice::Object>'
    Error executing cl.exe.
    
    MTC.exe - 8 error(s), 0 warning(s)
    

    Here is my stdafx.h
    // stdafx.h : include file for standard system include files,
    //      or project specific include files that are used frequently,
    //      but are changed infrequently
    
    #if !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_)
    #define AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    
    //
    // For VC6 and STLport
    //
    #if !defined(NDEBUG) && !defined(_STLP_DEBUG)
    #   define _STLP_DEBUG
    #endif
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    
    // Change this to the appropriate value to target Windows 98 and
    // Windows 2000 or later if not using VC6.
    #ifndef _WIN32_WINNT
    #  if defined(_MSC_VER) && _MSC_VER < 1500
    #    define _WIN32_WINNT 0x500
    #  endif
    #endif
    
    #ifndef WINVER
    #  if defined(_MSC_VER) && _MSC_VER > 1300
    #    define WINVER 0x0400
    #  endif
    #endif
    
    #ifndef _WIN32_IE                       // Allow use of features specific to IE 4.0 or later.
    #define _WIN32_IE 0x0400        // Change this to the appropriate value to target IE 5.0 or later.
    #endif
    
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    
    // turns off MFC's hiding of some common and often safely ignored warning messages
    #define _AFX_ALL_WARNINGS
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxtempl.h>
    #include <atlbase.h>
    //You may derive a class from CComModule and use it if you want to override
    //something, but do not change the name of _Module
    
    
    class CServiceModule : public CComModule
    {
    public:
    	HRESULT RegisterServer(BOOL bRegTypeLib, BOOL bService);
    	HRESULT UnregisterServer();
    	void Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, UINT nServiceNameID, const GUID* plibid = NULL);
        void Start();
    	void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        void Handler(DWORD dwOpcode);
        void Run();
        BOOL IsInstalled();
        BOOL Install();
        BOOL Uninstall();
    	LONG Unlock();
    	void LogEvent(LPCTSTR pszFormat, ...);
        void SetServiceStatus(DWORD dwState);
        void SetupAsLocalServer();
    
    //Implementation
    private:
    	static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        static void WINAPI _Handler(DWORD dwOpcode);
    
    // data members
    public:
        TCHAR m_szServiceName[256];
        SERVICE_STATUS_HANDLE m_hServiceStatus;
        SERVICE_STATUS m_status;
    	DWORD dwThreadID;
    	BOOL m_bService;
    };
    
    extern CServiceModule _Module;
    #include <atlcom.h>
    
    // add For ICE
    #include <WINSVC.H>
    #include <Ice/Ice.h>
    // add For ICE
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED)
    


    Tried a different order like this.

    extern CServiceModule _Module;
    #include <WINSVC.H>
    #include <atlcom.h>
    #include <Ice/Ice.h>

    vc6 compiling error such as follow.
    Compiling...
    StdAfx.cpp
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(82) : error C2146: syntax error : missing ';' before identifier 'm_hServiceStatus'
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(82) : error C2501: 'SERVICE_STATUS_HANDLE' : missing storage-class or type specifiers
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(82) : error C2501: 'm_hServiceStatus' : missing storage-class or type specifiers
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(83) : error C2146: syntax error : missing ';' before identifier 'm_status'
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(83) : error C2501: 'SERVICE_STATUS' : missing storage-class or type specifiers
    c:\documents and settings\940115\&#26700;&#38754;\mom mhlee\&#20462;&#25913; dcom to ice\mtc_0.2.0a1_20091204-dcom+ice\stdafx.h(83) : error C2501: 'm_status' : missing storage-class or type specifiers
    c:\ice-3.3.1-vc60\include\ice\proxy.h(549) : error C2027: use of undefined type 'Object'
            c:\ice-3.3.1-vc60\include\ice\objectf.h(20) : see declaration of 'Object'
    c:\ice-3.3.1-vc60\include\ice\proxy.h(549) : error C2039: 'ice_facet' : is not a member of 'ProxyHandle<class Ice::Object>'
    Error executing cl.exe.
    
    MTC.exe - 8 error(s), 0 warning(s)
    


    Thank you for help!
  • stanley20080628stanley20080628 Member Stanley LeeOrganization: Industrial Technology Research InstituteProject: Robot platform developer with messagebus
    Dear Benoit,

    Here is my stdafx.h in another order.
    // stdafx.h : include file for standard system include files,
    //      or project specific include files that are used frequently,
    //      but are changed infrequently
    
    #if !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_)
    #define AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    
    //
    // For VC6 and STLport
    //
    #if !defined(NDEBUG) && !defined(_STLP_DEBUG)
    #   define _STLP_DEBUG
    #endif
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    
    // Change this to the appropriate value to target Windows 98 and
    // Windows 2000 or later if not using VC6.
    #ifndef _WIN32_WINNT
    #  if defined(_MSC_VER) && _MSC_VER < 1500
    #    define _WIN32_WINNT 0x500
    #  endif
    #endif
    
    #ifndef WINVER
    #  if defined(_MSC_VER) && _MSC_VER > 1300
    #    define WINVER 0x0400
    #  endif
    #endif
    
    #ifndef _WIN32_IE                       // Allow use of features specific to IE 4.0 or later.
    #define _WIN32_IE 0x0400        // Change this to the appropriate value to target IE 5.0 or later.
    #endif
    
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    
    // turns off MFC's hiding of some common and often safely ignored warning messages
    #define _AFX_ALL_WARNINGS
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxtempl.h>
    #include <atlbase.h>
    //You may derive a class from CComModule and use it if you want to override
    //something, but do not change the name of _Module
    [COLOR="Red"]#include <WINSVC.H>	[/COLOR]
    
    class CServiceModule : public CComModule
    {
    public:
    	HRESULT RegisterServer(BOOL bRegTypeLib, BOOL bService);
    	HRESULT UnregisterServer();
    	void Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, UINT nServiceNameID, const GUID* plibid = NULL);
        void Start();
    	void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        void Handler(DWORD dwOpcode);
        void Run();
        BOOL IsInstalled();
        BOOL Install();
        BOOL Uninstall();
    	LONG Unlock();
    	void LogEvent(LPCTSTR pszFormat, ...);
        void SetServiceStatus(DWORD dwState);
        void SetupAsLocalServer();
    
    //Implementation
    private:
    	static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        static void WINAPI _Handler(DWORD dwOpcode);
    
    // data members
    public:
        TCHAR m_szServiceName[256];
        SERVICE_STATUS_HANDLE m_hServiceStatus;
        SERVICE_STATUS m_status;
    	DWORD dwThreadID;
    	BOOL m_bService;
    };
    
    extern CServiceModule _Module;
    [COLOR="Red"]#include <atlcom.h>
    // add For ICE
    #include <Ice/Ice.h>
    // add For ICE[/COLOR]
    
    
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED)
    
    


    vc6 compiling error such as follow.
    Linking...
    MTC.obj : error LNK2001: unresolved external symbol "public: unsigned short * __thiscall CString::AllocSysString(void)const " ([email protected]@@QBEPAGXZ)
    Utils.obj : error LNK2001: unresolved external symbol "public: unsigned short * __thiscall CString::AllocSysString(void)const " ([email protected]@@QBEPAGXZ)
    Debug/MTC.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    

    Thank you for help!
  • stanley20080628stanley20080628 Member Stanley LeeOrganization: Industrial Technology Research InstituteProject: Robot platform developer with messagebus
    Dear Benoit,

    After add include <afxdisp.h> , compile is done without error.


    // stdafx.h : include file for standard system include files,
    //      or project specific include files that are used frequently,
    //      but are changed infrequently
    
    #if !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_)
    #define AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    
    //
    // For VC6 and STLport
    //
    #if !defined(NDEBUG) && !defined(_STLP_DEBUG)
    #   define _STLP_DEBUG
    #endif
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    
    // Change this to the appropriate value to target Windows 98 and
    // Windows 2000 or later if not using VC6.
    #ifndef _WIN32_WINNT
    #  if defined(_MSC_VER) && _MSC_VER < 1500
    #    define _WIN32_WINNT 0x500
    #  endif
    #endif
    
    #ifndef WINVER
    #  if defined(_MSC_VER) && _MSC_VER > 1300
    #    define WINVER 0x0400
    #  endif
    #endif
    
    #ifndef _WIN32_IE                       // Allow use of features specific to IE 4.0 or later.
    #define _WIN32_IE 0x0400        // Change this to the appropriate value to target IE 5.0 or later.
    #endif
    
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    
    // turns off MFC's hiding of some common and often safely ignored warning messages
    #define _AFX_ALL_WARNINGS
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxtempl.h>
    #include <atlbase.h>
    //You may derive a class from CComModule and use it if you want to override
    //something, but do not change the name of _Module
    [COLOR="Red"]#include <WINSVC.H>	
    #include <afxdisp.h>
    [/COLOR]
    class CServiceModule : public CComModule
    {
    public:
    	HRESULT RegisterServer(BOOL bRegTypeLib, BOOL bService);
    	HRESULT UnregisterServer();
    	void Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, UINT nServiceNameID, const GUID* plibid = NULL);
        void Start();
    	void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        void Handler(DWORD dwOpcode);
        void Run();
        BOOL IsInstalled();
        BOOL Install();
        BOOL Uninstall();
    	LONG Unlock();
    	void LogEvent(LPCTSTR pszFormat, ...);
        void SetServiceStatus(DWORD dwState);
        void SetupAsLocalServer();
    
    //Implementation
    private:
    	static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
        static void WINAPI _Handler(DWORD dwOpcode);
    
    // data members
    public:
        TCHAR m_szServiceName[256];
        SERVICE_STATUS_HANDLE m_hServiceStatus;
        SERVICE_STATUS m_status;
    	DWORD dwThreadID;
    	BOOL m_bService;
    };
    
    extern CServiceModule _Module;
    [COLOR="Red"]#include <atlcom.h>
    // add For ICE
    #include <Ice/Ice.h>
    // add For ICE[/COLOR]
    
    
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__79092F73_F647_467E_9A0D_168EDC8A5666__INCLUDED)
    
    
Sign In or Register to comment.