Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7529427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:39:35+00:00 2026-05-30T04:39:35+00:00

Possible Duplicate: Why does VS2010 give syntax errors when syntax is correct? I’m trying

  • 0

Possible Duplicate:
Why does VS2010 give syntax errors when syntax is correct?

I’m trying to develop a kind of Windows 32 service in C language, using Visual Studio 2010.

I created a new project, and inserted .c files :

  • main.c
  • service.c
  • misc.c

I also have two header files :

  • myerrors.h
  • my.h

Here’s the code I have (be aware that it’s just a draft).

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)
{

}

My headers are just some function declarations and macros such as :

# 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_ */

While trying to compile the project, i got some weird errors :

my.h(19): error C2061: syntax error : identifier 'InstallMyService'
my.h(19): error C2059: syntax error : ';'
my.h(19): error C2059: syntax error : ')'

Or :

my.h(21): error C2061: syntax error : identifier 'InsertPathInRegistry'
my.h(21): error C2059: syntax error : ';'
my.h(21): error C2059: syntax error : 'type'

I checked on some forums that says those errors are commonly errors with includes badly placed, but I don’t really know in this case, I don’t think I made mistakes with includes…

Can anyone illuminate me ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:39:37+00:00Added an answer on May 30, 2026 at 4:39 am

    bool is not a data type in ANSI C. It is a data type in the C99 version of the language, only if <stdbool.h> is included, but Visual Studio does not support C99, only C89 (C99 also adds the _Bool data type, which can be used without including any headers).

    I suggest you replace bool with another type such as int, or use a typedef to alias it with int or unsigned char or something.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does 'unsigned temp:3' means I have been trying to learn raw
Possible Duplicate: Initializer syntax Short code sample to demonstrate (VS2010 SP1, 64-bit Win7): class
Possible Duplicate: Does const-correctness give the compiler more room for optimization? During the last
Possible Duplicate: Does anyone know of a good C# API for Subversion? I'm designing
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: What does map(&:name) mean in Ruby? I was watching a railscast and
Possible Duplicate: Why does C# not provide the C++ style ‘friend’ keyword? I'd like
Possible Duplicate: How does an underscore in front of a variable in a cocoa
Possible Duplicate: What does a type followed by _t (underscore-t) represent? While typing in
Possible Duplicate: What does ||= (or equals) mean in Ruby? It's hard to search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.