错误C2275:非法使用这种类型作为前pression [英] error C2275 : illegal use of this type as an expression
问题描述
从昨天开始,我一直面临的一个编译错误我的C项目。该项目本身由上创建一个服务,这将使一些任务。
Since yesterday, I've been facing a compiling error for my C project. The project itself consists on creating a service that will make some tasks.
我不什么从昨天开始改变了,但今天上午,我的code不能再编译。
I don't what has changed since yesterday, but this morning, my code can't compile anymore.
下面是我的错误:
c:\path\main.c(56): error C2275: 'SERVICE_TABLE_ENTRY' : illegal use of this type as an expression
c:\program files\microsoft sdks\windows\v7.0a\include\winsvc.h(773) : see declaration of 'SERVICE_TABLE_ENTRY'
c:\path\main.c(56): error C2146: syntax error : missing ';' before identifier 'DispatchTable'
c:\path\main.c(56): error C2065: 'DispatchTable' : undeclared identifier
c:\path\main.c(56): error C2059: syntax error : ']'
c:\path\main.c(57): error C2065: 'DispatchTable' : undeclared identifier
c:\path\main.c(57): warning C4047: 'function' : 'const SERVICE_TABLE_ENTRYA *' differs in levels of indirection from 'int'
c:\path\main.c(57): warning C4024: 'StartServiceCtrlDispatcherA' : different types for formal and actual parameter 1
这里的code。通过这些错误有关(从45行至58):
Here's the code concerned by these errors (from lines 45 to 58) :
int main(int ac, char *av[])
{
if (ac > 1)
{
if (!parse_args(ac, av))
{
aff_error(ARGUMENTS);
return EXIT_FAILURE;
}
}
SERVICE_TABLE_ENTRY DispatchTable[] = {{MY_SERVICE_NAME, ServiceMain}, {NULL, NULL}};
StartServiceCtrlDispatcher(DispatchTable);
return EXIT_SUCCESS;
}
这是我的ServiceMain函数的code:
And here's the code of my ServiceMain function :
void WINAPI ServiceMain(DWORD ac, LPTSTR *av)
{
gl_ServiceStatus.dwServiceType = SERVICE_WIN32;
gl_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
gl_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
gl_ServiceStatus.dwWin32ExitCode = 0;
gl_ServiceStatus.dwServiceSpecificExitCode = 0;
gl_ServiceStatus.dwCheckPoint = 0;
gl_ServiceStatus.dwWaitHint = 0;
gl_ServiceStatusHandle = RegisterServiceCtrlHandler(MY_SERVICE_NAME, ServiceCtrlHandler);
if (gl_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
return;
gl_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
gl_ServiceStatus.dwCheckPoint = 0;
gl_ServiceStatus.dwWaitHint = 0;
SetServiceStatus(gl_ServiceStatusHandle, &gl_ServiceStatus);
}
我不能设法找到一些答案适合我的问题,任何人都可以帮助?谢谢!
I couldn't manage to find some answers that fit my problem, could anyone helps ? Thanks !
推荐答案
当你的名字你的源文件 *。ç
,MSVC假定是编译C,这意味着C89。所有块的局部变量需要在块的开头声明。
When you name your source files *.c
, MSVC assumes it's compiling C, which means C89. All block-local variables need to be declared at the beginning of the block.
解决方法包括:
- 声明/在code块的开始初始化所有局部变量(开括号后直接
{
) - 的源文件重命名为
*。CPP
或同等学历并编译为C ++。 - 升级到VS 2013,这放宽此限制。
- declaring/initializing all local variables at the beginning of a code block (directly after an opening brace
{
) - rename the source files to
*.cpp
or equivalent and compile as C++. - upgrading to VS 2013, which relaxes this restriction.
这篇关于错误C2275:非法使用这种类型作为前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!