How to declare a "Windows type" in a mixed CLR project?

Frist, I apologize if this is not in the right forum but I simpyl could not think of a more appropriate one.

I am using VS C++ 2005 and I'm writing a project with mixed managed and native code (/CLR). In a native class I need to declare a HANDLE to an event but I get an endless sequence of build errors when I try to include "WinNT.h", where HANDLE is defined (according to the Windows API documentation).

The "DlDbEmu" project was started as a Windows Forms (wizard) project. Then, I added a native class "CDynoLAB" to it as follows:

#pragma once

#include "DynoLAB.h"

namespace DlDbEmu {

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 Microsoft::Win32;

[...]

public ref class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

DynoLAB = new CDynoLAB;

}

protected:

~Form1()

{

if (components)

{

delete components;

}

delete DynoLAB;

}

CDynoLAB *DynoLAB; // The one and only global instance of the CDynoLAB class

[...]

}

There are also several other native classes, which get included within CDynoLAB. What I am trying to do is declare a member variable of CDynoLAB that is of type HANDLE so that I can assign to it the result of a call to CreateEvent() later in the code. So I include "WinNT.h" at the top as follows:

#pragma once

#include "ChConfig.h"

#include "GrConfig.h"

#include "WinNT.h"

class CDynoLAB

{

public:

CDynoLAB(void);

public: // Public data members

CGrConfig m_GroupConfig; // The configuration information for DynoLAB logs (groups) within the current session

CChConfig m_ChConfig; // The channel configurations for all channels

float m_fCycleTime; // The DynoLAB base cycle time (seconds)

HANDLE m_hSessionSync; // "Session Sync" event

public: // Public member functions

void SetCycleTime(int CycleRate); // Set the DynoLAB cycle time

void Startup(void); // Perform the actions that DynoLAB would do at start time (i.e., before a session is defined)

};

When I try to build the project, I get tons of errors from WinNT.h - obviously, something is not being interpreted properly. I feel there should be multiple and simple solutions to this but I just can't put my finger on it. I would appreciate any help.

Kamen




Answer this question

How to declare a "Windows type" in a mixed CLR project?

  • Kimberly Blair

    What kind of errors are you getting



  • fourmi

    Have you tried just including windows.h and not to include winnt.h directly

    I believe including winnt.h directly (even without /CLR) will cause errors.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Matt Brunell

    I apologize, guys, it has been a while since I had been actively programming. Shortly after I posted the question, some dormant remembrance of past similar struggles came to me and even without having a specific idea what I wanted to do, I simply tried including Windows.h instead of WinNT directly. Naturally, it worked. What is with the Windows API documentation - why can't they say directly which header to include Here is what is in the documentation:

    Handle to an object.

    This type is declared in WinNT.h as follows:

    typedef PVOID HANDLE;

    This one is simple - basic stuff is all defined in Windows.h, and I should have known that, but there are many other libraries which are specified indirectly and it's tough to figure out which one is the right one to include.

    Anyway, thanks for the input!

    Kamen

  • How to declare a "Windows type" in a mixed CLR project?