可能性の重複:
Why does VS2010 give syntax errors when syntax is correct?エラーC2059とC2061
私は、Visual Studio 2010
を使用して、C言語でのWindows 32のサービスの種類を開発しようとしています私は新しいプロジェクトを作成し、.cファイルを挿入しました:
- main.cの
- service.c
- misc.c
私はまた、2つのヘッダファイルがあります。
- myerrors.h
- my.h
ここに私が持っているコードがあります(それは単なる草稿であることに注意してください)。
のmain.c:
#include <Windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "stdafx.h"
#include "my.h"
#include "myerrors.h"
static int parse_args(int ac, char **av)
{
int i = 0;
while (++i < ac)
if (strcmp(av[i], "-i") && !InstallMyService())
return false;
else if (strcmp(av[i], "-d") && !UninstallMyService())
return false;
else if (strcmp(av[i], "-p"))
if (!av[i + 1])
return false;
else
{
if (!InsertPathInRegistry(av[i + 1]))
return false;
i++;
}
else
return false;
return true;
}
int main(int ac, char **av)
{
HANDLE hLogFile;
if ((hLogFile = CreateFile(LOG_FILE_PATH, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
aff_error(CANT_CREATE_FILE);
if (ac > 1)
{
if (!parse_args(ac, av))
{
aff_error(BAD_ARGUMENTS);
return EXIT_FAILURE;
}
}
else
{
SERVICE_TABLE_ENTRY DispatchTable[] = {{DC_SERVICE_NAME, ServiceMain}, {NULL, NULL}};
StartServiceCtrlDispatcher(DispatchTable);
}
getchar();
if (!CloseHandle(hLogFile))
aff_error(CLOSE_FILE_FAILED);
return EXIT_SUCCESS;
}
misc.c:
#include <Windows.h>
#include <stdio.h>
#include "my.h"
#include "myerrors.h"
void aff_error(char *error_str)
{
fprintf(stderr, "ERROR: %s\n", error_str);
}
bool InsertPathInRegistry(char *path)
{
printf("LOG: Inserting %s as ", path);
}
void WriteInLogFile(HANDLE hLogFile, char *log_string)
{
printf("WriteInLogFile function");
}
service.c:
:#include <Windows.h>
#include "my.h"
bool InstallMyService()
{
return true;
}
bool UninstallMyService()
{
return true;
}
void WINAPI ServiceCtrlHandler(DWORD Opcode)
{
}
void WINAPI ServiceMain(DWORD ac, LPTSTR *av)
{
}
私のヘッダのようなだけで、いくつかの関数宣言とマクロです
# define DC_SERVICE_NAME "MyService"
/* MISC functions */
void aff_error(char *error_str);
my.h
#ifndef _MY_H_
# define _MY_H_
#include <Windows.h>
#include <strsafe.h>
/* Macros */
# define LOG_FILE_PATH "c:\\my_log_file.txt"
# define DC_SERVICE_NAME "MyService"
/* MISC functions */
void aff_error(char *error_str);
/* SERVICE functions */
void WINAPI ServiceMain(DWORD ac, LPTSTR *av);
bool InstallMyService();
bool UninstallMyService();
bool InsertPathInRegistry(char *path);
void WINAPI ServiceCtrlHandler(DWORD Opcode);
#endif /*!MY_H_ */
プロジェクトをコンパイルしようと、私はいくつかの奇妙なエラーを持っている間:私はそれらの言ういくつかのフォーラムで確認
my.h(21): error C2061: syntax error : identifier 'InsertPathInRegistry'
my.h(21): error C2059: syntax error : ';'
my.h(21): error C2059: syntax error : 'type'
:
my.h(19): error C2061: syntax error : identifier 'InstallMyService'
my.h(19): error C2059: syntax error : ';'
my.h(19): error C2059: syntax error : ')'
かをエラーは一般的に間違って配置されたものを含むエラーですが、私はこの場合は実際にはわかりませんが、私は間違いを含むと考えていません。
誰でも私を照らすことができますか?
ありがとうございました。
私たちに 'my.h'を見せてもらえますか? – cnicutar
@JamesMcNellis:ああ、それを逃した。その点については、 'bool' iircではなく' _Bool'です。 –
私の投稿を編集して 'my.h'を表示しましたが、あなたのコメントに私の答えがあるようです:) –