473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forward declaration of C# types in managed C++ headers

I'm working with C# objects from managed C++ using the gcroot template.
There'a a C++ header containing the definition of a C++ class:

#using <mscorlib.dll >
#include <vcclr.h>
#using <CSharpModule.d ll>

class CPlusPlusClass
{
....

gcroot<TLNameSp ace::SubNameSpa ce::SomeType*> _csharpInstance ;

....
}
and a C++ source file containing the class definition
#include "CPlusPlusClass .h"
using namespace TLNameSpace::Su bNameSpace;
void CPlusPlusClass: :createCSharp()
{
gcroot = new SomeType();
}

void CPlusPlusClass: :doSomething()
{
gcroot->someCSharpMeth od();
}

.....
In this example, I need the #using <CSharpModule.d ll> directive in the C++ header. One way to avoid this is
to split CPlusPlusClass into CPlusPlusInterf ace and CPlusPlus Implementation.
A more elegant technique in C++ would be a forward declaration for TLNameSpace::Su bNameSpace::Som eType in
the C++ header. However, I didn't find out how to do this.
The most promising try was

namespace TLNameSpace {
namespace SubNameSpace {
__gcc class SomeType;
}
}

At least the header compiled. On the #using <CSharpModule.d ll> line, I got an 'already defined' error.
Obviously C++ and C# namespaces are just a little bit the same ....

My question is:

- Is there a way to do the forward declaration described above ?
I'd appreciate any hint/solution for this
Nov 17 '05 #1
3 2241
You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vl******@nester ovsky-bros.com
home: http://www.nesterovsky-bros.com
I'm working with C# objects from managed C++ using the gcroot template.
There'a a C++ header containing the definition of a C++ class:

#using <mscorlib.dll >
#include <vcclr.h>
#using <CSharpModule.d ll>

class CPlusPlusClass
{
....

gcroot<TLNameSp ace::SubNameSpa ce::SomeType*> _csharpInstance ;

....
}
and a C++ source file containing the class definition
#include "CPlusPlusClass .h"
using namespace TLNameSpace::Su bNameSpace;
void CPlusPlusClass: :createCSharp()
{
gcroot = new SomeType();
}

void CPlusPlusClass: :doSomething()
{
gcroot->someCSharpMeth od();
}

.....
In this example, I need the #using <CSharpModule.d ll> directive in the C++
header. One way to avoid this is
to split CPlusPlusClass into CPlusPlusInterf ace and CPlusPlus
Implementation.
A more elegant technique in C++ would be a forward declaration for
TLNameSpace::Su bNameSpace::Som eType in
the C++ header. However, I didn't find out how to do this.
The most promising try was

namespace TLNameSpace {
namespace SubNameSpace {
__gcc class SomeType;
}
}

At least the header compiled. On the #using <CSharpModule.d ll> line, I got
an 'already defined' error.
Obviously C++ and C# namespaces are just a little bit the same ....

My question is:

- Is there a way to do the forward declaration described above ?
I'd appreciate any hint/solution for this

Nov 17 '05 #2
Thanx for the quick reply. Your suggestion would mean that I'd have to add a C# reference to any C++ module
that includes the C++ header. There's lots of them and I'd (for the moment) like to have the C++ <-> C#
interface encapsulated in one C++ module.

Vladimir Nesterovsky wrote:
You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vl******@nester ovsky-bros.com
home: http://www.nesterovsky-bros.com

I'm working with C# objects from managed C++ using the gcroot template.
There'a a C++ header containing the definition of a C++ class:

#using <mscorlib.dll >
#include <vcclr.h>
#using <CSharpModule.d ll>

class CPlusPlusClass
{
....

gcroot<TLNameSp ace::SubNameSpa ce::SomeType*> _csharpInstance ;

....
}
and a C++ source file containing the class definition
#include "CPlusPlusClass .h"
using namespace TLNameSpace::Su bNameSpace;
void CPlusPlusClass: :createCSharp()
{
gcroot = new SomeType();
}

void CPlusPlusClass: :doSomething()
{
gcroot->someCSharpMeth od();
}

.....
In this example, I need the #using <CSharpModule.d ll> directive in the C++
header. One way to avoid this is
to split CPlusPlusClass into CPlusPlusInterf ace and CPlusPlus
Implementatio n.
A more elegant technique in C++ would be a forward declaration for
TLNameSpace:: SubNameSpace::S omeType in
the C++ header. However, I didn't find out how to do this.
The most promising try was

namespace TLNameSpace {
namespace SubNameSpace {
__gcc class SomeType;
}
}

At least the header compiled. On the #using <CSharpModule.d ll> line, I got
an 'already defined' error.
Obviously C++ and C# namespaces are just a little bit the same ....

My question is:

- Is there a way to do the forward declaration described above ?
I'd appreciate any hint/solution for this


Nov 17 '05 #3
Thanx for the quick reply. Your suggestion would mean that I'd have to add a C# reference to any C++ module
that includes the C++ header. There's lots of them and I'd (for the moment) like to have the C++ <-> C#
interface encapsulated in one C++ module.

Vladimir Nesterovsky wrote:
You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vl******@nester ovsky-bros.com
home: http://www.nesterovsky-bros.com

I'm working with C# objects from managed C++ using the gcroot template.
There'a a C++ header containing the definition of a C++ class:

#using <mscorlib.dll >
#include <vcclr.h>
#using <CSharpModule.d ll>

class CPlusPlusClass
{
....

gcroot<TLNameSp ace::SubNameSpa ce::SomeType*> _csharpInstance ;

....
}
and a C++ source file containing the class definition
#include "CPlusPlusClass .h"
using namespace TLNameSpace::Su bNameSpace;
void CPlusPlusClass: :createCSharp()
{
gcroot = new SomeType();
}

void CPlusPlusClass: :doSomething()
{
gcroot->someCSharpMeth od();
}

.....
In this example, I need the #using <CSharpModule.d ll> directive in the C++
header. One way to avoid this is
to split CPlusPlusClass into CPlusPlusInterf ace and CPlusPlus
Implementatio n.
A more elegant technique in C++ would be a forward declaration for
TLNameSpace:: SubNameSpace::S omeType in
the C++ header. However, I didn't find out how to do this.
The most promising try was

namespace TLNameSpace {
namespace SubNameSpace {
__gcc class SomeType;
}
}

At least the header compiled. On the #using <CSharpModule.d ll> line, I got
an 'already defined' error.
Obviously C++ and C# namespaces are just a little bit the same ....

My question is:

- Is there a way to do the forward declaration described above ?
I'd appreciate any hint/solution for this


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
37090
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't explicitly say about enum's forward declaration, but one example shows it in 18.2.1, clause 4:
1
1911
by: qazmlp | last post by:
Is it a good style to re-forward declare the types, which were already forward declared in base header file, in derived class header file? // base.h class addrClass; class base { public: virtual void setAddress(addrClass* node);
6
5213
by: Steven T. Hatton | last post by:
Should I be able to forward declare something from a namespace different from the current one? For example the following code compiles: //testdriver.hpp #ifndef TESTDRIVER_HPP #define TESTDRIVER_HPP #include <ostream> namespace ns_testdriver{ using std::ostream;
2
4520
by: Plok Plokowitsch | last post by:
After over a decade of programming in C++ I seem to have missed some substantial point (mental note: am I getting too old for this?). A little bit of help would be *very* appreciated. I'm trying to gather various different classes into a common namespace using typedefs: class QWidget {}; class MyListview {}; namespace gui
1
2320
by: Steve | last post by:
Can anyone explain why C++ .NET compiler throws error for the following code segment: // Forward declaration of ListViewItemComparer class public __gc class ListViewItemComparer ; public __gc class CProgramLoaderForm : public System::Windows::Forms::Form { ListViewItemComparer* m_ListViewItemComparer ;
1
3082
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
2
508
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
1
5415
by: toton | last post by:
Hi, I have two namespace contains class InkFrame and PrefDialog respectively. PrefDialog needs InkFrame to show the dialog over the frame. It also stores a pointer to InkFrame inside it. Now I want InkFrame to be forward declared in the PrefDialog header file rather than to be included. I want to include it in the cpp file instead. There is no harm including it in PrefDialog header, and it works. But I want to save some compilation time....
6
8618
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in myfile.h template<typename T,typename R> class some_class;
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.