Please help on this strange Windows service only exception

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p align=left><font face=Arial size=2></font> 
Hi,
<p align=left> 
<p align=left>I used to use Visual Studio 6.3 to develop my application. The application is running as a Windows service on Windows XP SP2. This was working for so many years.
<p align=left> 
<p align=left>Now I want to compile my application in Visual Studio 2005 SP1 with Manifect generation enabled. The conversion seems to be ok. However, I run into one weird problem with Windows service.
<p align=left> 
When I disable the service from Service Control Manager, I was able to run my application all the way to the end without any warning.
<p align=left> 
<p align=left>When I enable the service, I will get exception immidiately after service starts. The stack trace indicates the problem is related to this:
<p align=left> 
<p align=left>EXCEPTION_RECORD:  ffffffff -- (.exr 0xffffffffffffffff)
ExceptionAddress: 782620c8 (mfc80d!AfxWinMain+0x00000078)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 00000000
Attempt to read from address 00000000
<p align=left>DEFAULT_BUCKET_ID:  NULL_POINTER_READ

<p align=left>Stack:
<p align=left> 
<p align=left>026cff3c 005d9d7b 00400000 00000000 0015234a mfc80d!AfxWinMain+0x78
<p align=left> 
<p align=left>Attach VS 2005 to the process shows the stack at:
<p align=left>  <font size=2><font size=2>
BOOL CWinApp::_LoadSysPolicies() </font><font color="#0000ff" size=2>throw</font><font size=2>()
</font></font><font size=2>{</font>
<p align=left>     ...
<p align=left>     <font size=2> <font size=2>
_AfxSysPolicies *pPolicies = rgPolicies;
_AfxSysPolicyData *pData = NULL;
</font><font color="#0000ff" size=2>while</font><font size=2> (pPolicies->szPolicyKey != NULL)
{
</font><font color="#0000ff" size=2>if</font><font size=2> (ERROR_SUCCESS == ::RegOpenKeyEx(                 <- This line crashes
HKEY_CURRENT_USER,
pPolicies->szPolicyKey,
NULL,
KEY_QUERY_VALUE,
&hkPolicy
))
<p align=left>.....
<p align=left>}
<p align=left> 
This function is called in InitApplication() which is called by AfxWinMain().
<p align=left> 
<p align=left>I need to fix this problem, but I dont have much clue why this is happening. Could it be possible that Windows Service does not like SxS MFC DLL? or some initialization step is required to run an application in Windows service if Manifest is used?
<p align=left> 
<p align=left>Anyway, I dont have a clue yet. I hope some gurus there can help me to resolve this.
<p align=left> 
<p align=left>Thanks,
<p align=left> 
<p align=left>zhongsheng</font></font>

View the full article
 
Back
Top