How to #include <someheader.h> in the managed code?

  • Thread starter Thread starter Viktor
  • Start date Start date
V

Viktor

Hi everybody,
Perhaps this question is obvious, but I spent whole day trying to make
it work to no avail.

Here is the scenario:
I am using VC++ .Net, Forms. I created a simple Form project, dropped
couple of controls on the form. Now I am trying to call
GetProfileSection(...) to read values from .ini file. IDE seems to
know this function, since it shows parameter list as a tooltip as soon
as I type "GetProfileSection(".

But when I am trying to build it, I am getting "GetProfileSection:
identifier not found..." error. GetProfileSection is declared in
winbase.h, but if I try to add #include <winbase.h>, I am getting 78
errors in winbase.h, which cannot be true. Same happens with calls to
other functions, declared in other headers.

I was trying to find an explanation on a web but couldn't, although
there must be some simple explanation.

Any help would be greatly appreciated.

Viktor

Below is a top portion of my Form1.h, (the unit that contains buttons'
OnClick events etc, where I am trying to call GetProfileSection)

#pragma once

namespace Test1
{
#include<string.h>
#include <winbase.h> // Is this correct place to include .h?

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::Runtime::InteropServices;
 
Viktor,
Hi everybody,
Perhaps this question is obvious, but I spent whole day trying to make
it work to no avail.

Here is the scenario:
I am using VC++ .Net, Forms. I created a simple Form project, dropped
couple of controls on the form. Now I am trying to call
GetProfileSection(...) to read values from .ini file. IDE seems to
know this function, since it shows parameter list as a tooltip as soon
as I type "GetProfileSection(".

But when I am trying to build it, I am getting "GetProfileSection:
identifier not found..." error. GetProfileSection is declared in
winbase.h, but if I try to add #include <winbase.h>, I am getting 78
errors in winbase.h, which cannot be true. Same happens with calls to
other functions, declared in other headers.

I was trying to find an explanation on a web but couldn't, although
there must be some simple explanation.

Any help would be greatly appreciated.

Viktor

Below is a top portion of my Form1.h, (the unit that contains buttons'
OnClick events etc, where I am trying to call GetProfileSection)

#pragma once

namespace Test1
{
#include<string.h>
#include <winbase.h> // Is this correct place to include .h?

Don't include winbase.h, instead include windows.h. Also, move the #includes
to outside of the namespace declaration. In fact, you'd do better off just
moving them altogether to your stdafx.h precompiled header, it should speed
up your compile times.
 
Viktor said:
GetProfileSection is declared in
winbase.h, but if I try to add #include <winbase.h>, I am getting 78
errors in winbase.h, which cannot be true.
Below is a top portion of my Form1.h, (the unit that contains buttons'
OnClick events etc, where I am trying to call GetProfileSection)

#pragma once

namespace Test1
{
#include<string.h>
#include <winbase.h> // Is this correct place to include .h?

Don't ever put an #include inside a namespace. All the included stuff
will be inside the namespace Test1, which is not where it is supposed to
be. Move the #includes to global scope, before "namespace Test1".
 
Back
Top