S
Shawn B.
Greetings,
I'm trying to create a Managed C++ library that extends the console features
beyond System::Console capabilities. I chose MC++ over C++/CLI because I
need it to work on the 1.1 framework. I haven't programmed C++ in years and
I'm very very new to Managed C++. Thus, I'm having issues getting even the
simplest thing to work, and not for the fact, that finding good information
about using API calls and such from within a managed class isn't as easy to
find as I thought it would be.
In particular, my true lack of understanding is this: I have a __gc class.
I'm using win32 api. So I need to pass a native struct into a native method
call. Do I need to do anything special at this point, such as mark it __gc*
or something?
The following code won't compile. Was wondering if anyone could explain how
to make it compile. I marked the offending line of code with a comment.
Search for "Compile error"
* common.h
* console.h
* console.cpp
* stdafx.h
common.h
--------
#pragma once
#if !defined (common_h)
#define common_h
// .NET Access Modifiers
//
#define PUBLIC public public
#define PROTECTED public protected
#define PRIVATE private private
#define INTERNAL private public
#endif // !defined (common_h)
--------
console.h
--------
#pragma once
using namespace System;
namespace Test
{
public __gc class Console
{
PUBLIC:
PROTECTED:
PRIVATE:
const static byte EMPTY = 32;
const static int CAPTION_LENGTH = 1024;
static HANDLE hConsoleOutput; // handle to output buffer
static HANDLE hConsoleInput; // handle to input buffer
static int OriginalConsolePen;
static int CurrentConsolePen;
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
static COORD ConsoleOutputLocation;
public:
static void Clear();
};
}
----------
console.cpp
----------
// This is the main DLL file.
#include "stdafx.h"
#include "console.h"
namespace Test
{
void Console::Clear()
{
DWORD chars = 0;
CONSOLE_SCREEN_BUFFER_INFO info;
COORD home;
home.X = 0;
home.Y = 0;
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
hConsoleInput = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOutput, &consoleInfo); // <-- Compile
error happens here
if (GetConsoleScreenBufferInfo(hConsoleInput, &info) == 0) {
System::Console::Write(S"\x0c");
return;
}
FillConsoleOutputCharacter(
hConsoleOutput,
EMPTY,
info.dwSize.X * info.dwSize.Y,
home,
&chars
);
FillConsoleOutputAttribute(
hConsoleOutput,
CurrentConsolePen,
info.dwSize.X * info.dwSize.Y,
home,
&chars
);
SetConsoleCursorPosition(
hConsoleOutput,
home
);
}
}
--------
stdafx.h
---------
#pragma once
#include <wtypes.h>
#include <wincon.h>
#include "common.h"
I'm trying to create a Managed C++ library that extends the console features
beyond System::Console capabilities. I chose MC++ over C++/CLI because I
need it to work on the 1.1 framework. I haven't programmed C++ in years and
I'm very very new to Managed C++. Thus, I'm having issues getting even the
simplest thing to work, and not for the fact, that finding good information
about using API calls and such from within a managed class isn't as easy to
find as I thought it would be.
In particular, my true lack of understanding is this: I have a __gc class.
I'm using win32 api. So I need to pass a native struct into a native method
call. Do I need to do anything special at this point, such as mark it __gc*
or something?
The following code won't compile. Was wondering if anyone could explain how
to make it compile. I marked the offending line of code with a comment.
Search for "Compile error"
* common.h
* console.h
* console.cpp
* stdafx.h
common.h
--------
#pragma once
#if !defined (common_h)
#define common_h
// .NET Access Modifiers
//
#define PUBLIC public public
#define PROTECTED public protected
#define PRIVATE private private
#define INTERNAL private public
#endif // !defined (common_h)
--------
console.h
--------
#pragma once
using namespace System;
namespace Test
{
public __gc class Console
{
PUBLIC:
PROTECTED:
PRIVATE:
const static byte EMPTY = 32;
const static int CAPTION_LENGTH = 1024;
static HANDLE hConsoleOutput; // handle to output buffer
static HANDLE hConsoleInput; // handle to input buffer
static int OriginalConsolePen;
static int CurrentConsolePen;
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
static COORD ConsoleOutputLocation;
public:
static void Clear();
};
}
----------
console.cpp
----------
// This is the main DLL file.
#include "stdafx.h"
#include "console.h"
namespace Test
{
void Console::Clear()
{
DWORD chars = 0;
CONSOLE_SCREEN_BUFFER_INFO info;
COORD home;
home.X = 0;
home.Y = 0;
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
hConsoleInput = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOutput, &consoleInfo); // <-- Compile
error happens here
if (GetConsoleScreenBufferInfo(hConsoleInput, &info) == 0) {
System::Console::Write(S"\x0c");
return;
}
FillConsoleOutputCharacter(
hConsoleOutput,
EMPTY,
info.dwSize.X * info.dwSize.Y,
home,
&chars
);
FillConsoleOutputAttribute(
hConsoleOutput,
CurrentConsolePen,
info.dwSize.X * info.dwSize.Y,
home,
&chars
);
SetConsoleCursorPosition(
hConsoleOutput,
home
);
}
}
--------
stdafx.h
---------
#pragma once
#include <wtypes.h>
#include <wincon.h>
#include "common.h"