请帮助解决这个奇怪的Windows服务异常 [英] Please help on this strange Windows service only exception

查看:65
本文介绍了请帮助解决这个奇怪的Windows服务异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用Visual Studio 6.3来开发我的应用程序。该应用程序在Windows XP SP2上作为Windows服务运行。这工作了很多年。

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.

现在我想用Manifect在Visual Studio 2005 SP1中编译我的应用程序生成启用。转换似乎没问题。但是,我在Windows服务中遇到了一个奇怪的问题。

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.

当我从服务控制管理器中禁用该服务时,我能够在没有任何警告的情况下一直运行我的应用程序。

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.

当我启用服务时,我会服务开始后立即获得例外。堆栈跟踪表明问题与此相关:

When I enable the service, I will get exception immidiately after service starts. The stack trace indicates the problem is related to this:

EXCEPTION_RECORD:ffffffff - (.exr 0xffffffffffffffff)< br> ExceptionAddress:782620c8(mfc80d!AfxWinMain + 0x00000078)
ExceptionCode:c0000005(访问冲突)
ExceptionFlags:00000000
NumberParameters:2
参数[0]:00000000
参数[1] :00000000
尝试从地址00000000读取

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

DEFAULT_BUCKET_ID:NULL_POINTER_READ

DEFAULT_BUCKET_ID:  NULL_POINTER_READ

堆栈:

026cff3c 005d9d7b 00400000 00000000 0015234a mfc80d!AfxWinMain + 0x78

026cff3c 005d9d7b 00400000 00000000 0015234a mfc80d!AfxWinMain+0x78

将VS 2005附加到进程显示堆栈位于:

Attach VS 2005 to the process shows the stack at:

BOOL CWinApp :: _ LoadSysPolicies() throw ()

BOOL CWinApp::_LoadSysPolicies() throw()

{

...

    

_AfxSysPolicies * pPolicies = rgPolicies;

_AfxSysPolicies *pPolicies = rgPolicies;

_AfxSysPolicyData * pData = NULL;

_AfxSysPolicyData *pData = NULL;

(pPolicies-> szPolicyKey!= NULL)

while (pPolicies->szPolicyKey != NULL)

{

if (ERROR_SUCCESS == :: RegOpenKeyEx(< - 此行崩溃

if (ERROR_SUCCESS == ::RegOpenKeyEx(                 <- This line crashes

HKEY_CURRENT_USER,

HKEY_CURRENT_USER,

pPolicies-> szPolicyKey,

pPolicies->szPolicyKey,

NULL,

KEY_QUERY_VALUE,

KEY_QUERY_VALUE,

& hkPolicy

&hkPolicy

))

.....

}

此函数在InitApplication()中调用,由AfxWinMain()调用。

This function is called in InitApplication() which is called by AfxWinMain().

我需要解决这个问题,但我不知道为什么会发生这种情况。 Windows服务可能不喜欢SxS MFC DLL吗?如果使用Manifest,在Windows服务中运行应用程序需要一些初始化步骤吗?

I need to fix this problem, but I don't 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?

无论如何,我不喜欢还没有线索。我希望那里的一些大师可以帮我解决这个问题。

Anyway, I don't have a clue yet. I hope some gurus there can help me to resolve this.

谢谢,

zhongsheng

zhongsheng

推荐答案

我以前的帖子在故障位置方面不准确。

My previous post was not accurate in term of the fault location.

现在我添加DebugBreak()进入我的应用程序构造函数,然后从VS 2005附加服务。

Now I add DebugBreak() into my application constructor and then attach the service from VS 2005.

例外情况发生在AfxWinMain()中:

The exception happens in AfxWinMain():

CWinThread * pThread = AfxGetThread();

CWinThread * pThread = AfxGetThread();

CWinApp * pApp = AfxGetApp();

CWinApp * pApp = AfxGetApp();

...

if(!pThread-> InitInstance() )< ----- pThread为NULL。

if (!pThread->InitInstance())                                   <----- pThread is NULL.

{

....

}

问题似乎归结为AfxGetThread()。 Windows Service和独立应用程序之间的这个功能有什么区别?显示会导致任何问题吗?

The problem seems to be boiled down to AfxGetThread(). What is the difference of this function between Windows Service and standalone application? Will manifest cause any problem?

谢谢,

zhongsheng

zhongsheng


这篇关于请帮助解决这个奇怪的Windows服务异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆