gpt4 book ai didi

C++ Windows 服务错误 1063

转载 作者:太空狗 更新时间:2023-10-29 23:05:56 31 4
gpt4 key购买 nike

尝试开发我的第一个 Windows 服务,我正在 Windows 7 MS VC++ 10.0 中调试。它一调用 StartServiceCtrlDispatcher(),我就收到错误 1063,它说访问被拒绝。我是管理员,我该如何通过呢?我是服务新手。谢谢。代码:

// For WinXp, don't forget to link to
// Advapi32.lib library if needed...

#define _WIN32_WINNT 0x0501

#include <windows.h>

#include <stdio.h>
#include <tchar.h>

// Prototypes, just empty skeletons...

void SvcDebugOut(LPSTR String, DWORD Status);
void WINAPI MyServiceCtrlHandler(DWORD opcode);
void MyServiceStart(DWORD argc, LPTSTR *argv);
DWORD MyServiceInitialization(DWORD argc, LPTSTR *argv, DWORD *specificError);

void main()
{

// Using 2-D array as a table...

// The name of a service to be run in this service process - "MyService",

// The function as the starting point for a service - MyServiceStart or

// a pointer to a ServiceMain() function...

// The members of the last entry in the table must have NULL values

// to designate the end of the table...

SERVICE_TABLE_ENTRY DispatchTable[] = {{_TEXT("MyService"), (LPSERVICE_MAIN_FUNCTION)MyServiceStart}, {NULL, NULL}};
if (!StartServiceCtrlDispatcher(DispatchTable))
SvcDebugOut("StartServiceCtrlDispatcher() failed, error: %d\n", GetLastError());
else
printf("StartServiceCtrlDispatcher() looks OK.\n");
return;
}

// ==========================================================================
// Prototype definitions...just skeletons here...
void WINAPI MyServiceCtrlHandler(DWORD opcode)
{
// Service control information here...
return;
}

void MyServiceStart(DWORD argc, LPTSTR *argv)
{
// Starting service information here...
return;
}



DWORD MyServiceInitialization(DWORD argc, LPTSTR *argv, DWORD *specificError)
{
// Service initialization information here...
return 0;
}

// Very simple info to the standard output...
void SvcDebugOut(LPSTR String, DWORD Status)
{
CHAR Buffer[1024];
printf("In SvcDebugOut() lol!\n");
if (strlen(String) < 1000)
{
sprintf(Buffer, String, Status);
OutputDebugStringA(Buffer);
}
else
printf("String too long...\n");
return;
}

最佳答案

post正确回答。只要您不将服务“作为服务”启动,它就不会工作。

您需要注册它。为此,请查看此 file ,它是 Apple bonjour 服务实现,它是开源的。

它很好地说明了安装服务必须做什么。特别是方法 InstallService - 和 RemoveService(如果你想删除它)。

关于C++ Windows 服务错误 1063,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17377037/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com