|
|
Comments and Discussions
|
|
 |

|
Hi Vagif,
I'm try to migrate to .NET 3.5 (Visual Studio 2008), but my system is giving me a E_ACCESSDENIED when AtlServiceModule try to execute "RegisterAppId".
I read in msdn, internet and nothing about this error. I'm using Windows 7 now. May be WM7?. I believe that all problem are security gratts, but where???, or how??, My User is Administrator.
is the first time that happend to me and can't find information to help me, could you help me with the error?, please.
Thks
|
|
|
|

|
Hi Vagif,
I have a response to my own XD, is only security credentials, in visual studio->tools->command prompt execute
MyServiceNew -service and install perfectly.
But with my user account (used to login) can't install.
|
|
|
|
|

|
Hi,
I've created a service in VC++ (unmanaged code) on Visual Studio 2005. Everything works fine.
But I still have a problem to stop my service.
During its termination, my service needs time to communicate with external components (about 5 minutes).
When I stop my service from the "Control manager", my service enters in a STOP_PENDING state. I start a independant thread which refresh its status by calling regularly SetServiceStatus.
But the "Control Manager" generates a 1053 error after a timeout of about 2 minutes.
After several days of work, can't find the reason, so need help.
For information, these my code:
void CMyServiceModule::OnStop()
{
this->LogEvent(_T("SERVICE_STOP_PENDING"));
m_status.dwWaitHint = 10000;
m_status.dwCheckPoint = 1;
SetServiceStatus(SERVICE_STOP_PENDING);
_beginthread( StopFunct, 0, (void *) this );
// PostThreadMessage(m_dwThreadID, WM_QUIT, 0, 0);
}
void StopFunct( void *ch )
{
CMyServiceModule *pThis= (CMyServiceModule *)ch;
SERVICE_STATUS m_status = pThis->m_status;
pThis->LogEvent(_T("CMyServiceModule::PStopFunct() %d"),GetTickCount());
DWORD dwStart = GetTickCount();
dwStart += 300000;
pThis->LogEvent(_T("Waiting %d %d %d %d"),dwStart,GetTickCount(), m_status.dwCheckPoint, m_status.dwWaitHint);
while (dwStart>GetTickCount()) {
m_status.dwWaitHint += 10000;
m_status.dwCheckPoint++;
pThis->SetServiceStatus(SERVICE_STOP_PENDING);
pThis->LogEvent(_T("Waiting %d %d %d %d"),dwStart,GetTickCount(), m_status.dwCheckPoint, m_status.dwWaitHint);
Sleep(3000);
}
pThis->LogEvent(_T("Waiting %d %d %d %d"),dwStart,GetTickCount(), m_status.dwCheckPoint, m_status.dwWaitHint);
pThis->SetServiceStatus(SERVICE_STOPPED);
PostThreadMessage(pThis->m_dwThreadID, WM_QUIT, 0, 0);
}
Thanks in advance....
Fred
|
|
|
|

|
Vagif,
I have a question on control the servce of Window.
I am using VC ++ 6.0 and devloping MFC program now.
When the user launch my application, the application
needs to check the service named SV2000. If the service is started,
the application has to set it to stop state.
When the application exit, it has to set the service to started.
How can I do it ? Do you have example code ?
I am new on this
Thanks,
Jian
|
|
|
|
|

|
How can i make the service auto_start?
when i use vc.net appwizard i create a service which had to be manual started.How can i make it auto_start?
|
|
|
|

|
why ATL 7 dll don't regsvr32.exe in no install VC 7 os
but VC 6 is regsvr32.exe ok
|
|
|
|

|
First:
You must copy C:\windows\system32\msvcr71d.dll from your computer to no install VC 7 os.
Second:
You can use regsvr32.exe to register you ATL.Try it.
Jack Chang
|
|
|
|

|
Hi ,
i'm stuck in really strange problem.
I'd devloped a windows service using above method in VC++.net. This service has an interface exposed.
I'm facing following problems.
1)In installer code of .net i used command "servicepath" -service to install the service.
at this point service installs and starts(as it is created in automatic mode).
But when i tried to access that interface throught other windows application ,it gives error,'queryinterface on object failed'.
If i unregisters same service from command line and registers it using same command,it works fine.
what would be problem.
2) what would be ideal installer for this service?how to achive that?
thanks ,
prasad
|
|
|
|

|
If you use ATL-generated code, then running "servicepath" -service it not enough. You should run the following commands:
"servicepath" -RegServer
"servicepath" -Service
And in this order! First command will register COM object(s), and the second one registers Windows service. Try this.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|

|
thanks, this solved my problem.
Now i dare to tell you some more problems,
1.
by default service created is in manual mode, to make it automatic i'd overriden function Install to create service in automatic mode,
I've overridden RegisterAppId to call this install function.
Now when i installs service it starts in auto mode.
But i observed one thing, after rebooting for three or four times on windows2000 server,it fails to start on reboot.
But if i try to start it manually it works fine.
2.
after installation my service start in auto mode.
If stops and starts again.it works fine.
but if i unintalls it it become disabled(mark for deletion). Can i supress this behaviou?
thanks,
Prasad
|
|
|
|

|
I'm wondering how to use the ATL server from a client that is running as a USER on the local machine? I'm getting the E_ACCESSDENIED error code...
Best regards,
/Christian
|
|
|
|

|
try using dcomcnfg.exe to give access rights to logged on user,
try restarting machine.
prasad
|
|
|
|

|
I was really happy to find out why my perfectly working ATL3 service would not work with ATL 7. Thanks Vagif.
I rushed to copy/paste this code
#if _ATL_VER == 0x0700
if (SUCCEEDED (hr) && !m_bDelayShutdown)
hr = CoResumeClassObjects();
#endif
into my file and was surprised again - it still would not work. After a few minutes it dawned on me that it should be #if _ATL_VER >= 0x0700 because I am using ATL 7.1.
That is my 5 cents.
|
|
|
|

|
Vagif and all,
This is excellent work. I'm struggling, though, how to use startup parameters. Vagif's code no longer uses this:
inline void CServiceModule::ServiceMain(DWORD /* dwArgc */, LPTSTR* /* lpszArgv */)
Where should my code do argc/argv processing?
Thanks for the great code,
Erik Ostermueller
erik.ostermueller@fnf.com
|
|
|
|

|
My VC6 generated windows service project supported MFC. But after migrating my code to ATL7 as you suggested I noticed that I can't use MFC any more. As soon as I include AFXWIN.h in the stdafx.h file I get this compile error in my server.cpp file:
"error C2504: 'CAtlServiceModuleT' : base class undefined"
If I remove afxwin.h from stdafx.h file then it compiles ok but then I have no MFC support. A lot of my code depends on MFC and it also links with other MFC DLLs so I can't really get rid of MFC. Is there a way to make ATL7 to co-exist with MFC? And why would Microsoft stop supporting that without notice!?
Any help would be much appreciated because I am stuck at this point.
Thanks.
|
|
|
|

|
No one replied to this post so I decided to do my own research. Since ATL7 has a lot of the functionality of MFC built into it, including the two libraries in your StdAfx.h file can cause the compile problem. To fix it first make sure to include MFC header files BEFORE including ATL headers, and then just add a "#undef _AFX" after the MFC header files, like shown below:
// Contents of StdAfx.h file
...
#include
#include
#undef _AFX
#include
#include
using namespace ATL;
...
Good Luck!
|
|
|
|
|

|
I had this same problem...
And the easiest way to solve this was to create a new version of atlbase.h
without the _afx define arround CAtl...ModuleT!
I was able to craft a solution using the #undef _AFX but it only worked when i was not
using attributed code!
The main problem I see with this solution is that there must be a vaslid reason for the #ifdef _AFX, but until now the services are running fine using some classes from the MFC library!
Kind Regards
|
|
|
|

|
Remarks from MSDN:
In Visual Studio .NET 2003, this method is not implemented in the base class. The Visual Studio project wizard includes this method in the generated code, but a compilation error will occur if a project created in an earlier version of Visual C++ is compiled using ATL 7.1. Any class that derives from CAtlServiceModuleT must implement this method in the derived class. The method has to call CoInitializeSecurity and provide the appropriate security settings for the service.
Use PKT-level authentication, impersonation level of RPC_C_IMP_LEVEL_IDENTIFY and an appropriate non-null security descriptor in the call to CoInitializeSecurity.
For wizard-generated nonattributed service projects, this would be in
class CXXXModule : public CAtlServiceModuleT< CXXXModule, IDS_SERVICENAME > // XXX is the Project Name
{
public :
DECLARE_LIBID(...)
DECLARE_REGISTRY_APPID_RESOURCEID(...)
HRESULT InitializeSecurity() throw()
{
// TODO : Call CoInitializeSecurity and provide the
// appropriate security settings for your service.
// Suggested - PKT Level Authentication,
// Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY
// and an appropiate Non NULL Security Descriptor.
return S_OK;
}
};
For attributed service projects, this would be in
[module(service, ...)] // Comment out any ; after the ]
class CXXXModule // XXX is the Project Name
{
public:
HRESULT InitializeSecurity() throw()
{
// TODO : Call CoInitializeSecurity and provide the
// appropriate security settings for your service.
// Suggested - PKT Level Authentication,
// Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY
// and an appropiate Non NULL Security Descriptor.
return S_OK;
}
};
|
|
|
|

|
Also, you have to add _tWinMain:
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int nShowCmd)
{
return _Module.WinMain(nShowCmd);
}
Don't drink and drive - smoke and fly
|
|
|
|

|
If you've come from the ATL3.0 wizard to 2003, it is a simple matter to just cut and paste the snippet from the generated "Run" method :
HRESULT InitializeSecurity() throw () {
CSecurityDescriptor sd;
sd.InitializeFromThreadToken();
HRESULT hr = CoInitializeSecurity(sd, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, NULL);
return hr;
}
There's always sunshine after rain
|
|
|
|

|
Hi Vagif,
Thanks very much for you article, it was very useful for me.
I have a question to you though... I need to change the description of the service and I used to do it in Install() method in VS6. But it looks like that I can't override the Install() method from CAtlServiceModuleT. I would be greatful for any idea on what's the best place for this configuration changes...
Thank you
|
|
|
|

|
I try to use the program of the article :
Toolband (Toolbar for IE) sample using WTL
http://www.codeproject.com/wtl/toolband.asp?target=band%7Csample
But I don't know, with what replace atlapp.h in the program ?
NB: It's a good article.
|
|
|
|

|
I'm not sure I understood the question. The article about Windows services written with ATL. There's nothing about toolbars, and about atlapp.h. Where does it come from?
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|

|
The problem of this article is in the Migrating ATL applications to Visual C++.NET because there is a bug during the compilation.
The file atlapp.h don't exist in Visual C++.NET and I can't find good informations on this subject.
|
|
|
|

|
Do you use Visual Studio.NET 2003? The article was written and tested with VS.NET 2002. Anyway, I don't include any atlapp.h in any of the sample files.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|

|
Thank you, keyphy, for support.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|

|
I face some problem in ATL com service.
1. I create a ATL service in VC++ 6.0. call the com object in Vb application.
My problem is :- when I terminate the Vb application autometicaly my service has killed. my requirment is my service is running contiounsly until my system is reboot or userkill manulay?
|
|
|
|

|
Your problem is that event though your create your application as a service, unless you register and start it properly, it can still be instantiated as a regular out-of-proc COM component, i.e. it will terminate when client is finished with it.
Make sure you register your service by running " -Service" command. AFAIK, ATL6 has a bug there, so you have to register service after registering COM objects (-RegServer option). Then start a service either from ControlPanel or by issuing "net start " from a command prompt.
Hope this helps.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|

|
I have done the said steps for installing the sample as Windows service on XP.
But when i call the service object thru client1 app, the service stops responding and i cannot start or stop. when i try net start , i get this" The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.". How to avoid the service from becomg like this ?
|
|
|
|
|

|
Hi There,
Sorry for asking. I'm a newby, but learning C++ very fast now.
Great article, but one question refering the ATL7 Service (samples are hard to find, maybe someone could send something...(j.voskuil@wanadoo.nl) I need to write a service that must process a text file every 5 min. So I must create a loop. But's a service, so there must be a processing loop (RunMessageLoop????). I can't find where i must put my code.
Can someone help?
With kind regards,
Joost Voskuil
|
|
|
|

|
I am in the same situation! Microsoft's documentation is very sparse and I can't find any examples on how to do this.
|
|
|
|

|
How about creating your application thread in PreMessageLoop, then kill it in PostMessageLoop.
|
|
|
|
|

|
Hi Vagif! Unfortunately the MyService2 - Project you are talking about in your article can't be build. There are some missing files like "MyService2.h" and trying to build proxy/stub (nmake -f MyService2ps.mk) ends with fatal error U1073: don't know how to make 'dlldata.obj'. Sorry... I'm not sure you have checked this project before posted to the web.
Stefano
|
|
|
|

|
Hi Stefano,
I always verify projects before posting them to the Web. I wouldn't waste your time on project that can't be built But there is an assumptions I make - I assume you will be using Visual Studio .NET to build the project. The file that you refer to (MyService2.h) does not belong to the source code. This file is automatically generated when you run MIDL compiler on MyService2.idl. MIDL produces several files that are used to generate output binaries. So you can't just run nmake on MyService2ps.mk without running MIDL first. I suggest you load MyService2.sln into Visual Studio .NET and build it. It should solve your problem.
Best regards
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|

|
In vc 6.0, to do this , just include "afxtempl.h" before "atlbase.h" and use MFC in shared dll.But, In VC.net, I found this can not work, It wiil give an compile error "the symbol of CAtlServiceModultT can't be found".
How to do, any hint will be appreciated.
|
|
|
|

|
I don't know .NET, however, you can work with STL (std::vector)
|
|
|
|

|
Thanks for the great article. I found it very useful.
- Scott
|
|
|
|

|
Thank you Scott.
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|

|
As in subject.
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining.
Said byRoger Wright about me.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
Guidelines to migrate ATL-based Windows service application to Visual C++.NET
| Type | Article |
| Licence | |
| First Posted | 28 Jul 2002 |
| Views | 176,652 |
| Bookmarked | 52 times |
|
|