473,695 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheriting the VC++ template classes into C#.net

Amu
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

Jan 16 '07 #1
7 2497
Amu a écrit :
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .
I may be wrong, but I really believe that composition
(http://en.wikipedia.org/wiki/Object_composition) is the only way to
achieve what you are trying to.

Mathieu
Jan 16 '07 #2
Amu

Mathieu Cartoixa wrote:
Amu a écrit :
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .
I may be wrong, but I really believe that composition
(http://en.wikipedia.org/wiki/Object_composition) is the only way to
achieve what you are trying to.

Mathieu
i read the solution but can u give me some clear idea regarding
it.actually i have a dll ( template class) ready which is written in
VC++6. But presently i need to inherit its classes into my new C#./net
project.so if there is some better solution with u then please give me
the solution.
:Amu

Jan 16 '07 #3
Amu wrote:
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .
Hi,

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.
You can use generics and map them to the associated template class.
Though generics are more restricted than templates, so you possibly
can't directly wrap the template classes by using generics.

Another solution would be wrapping the template classes in COM
interfaces or by using flat functions. Surely with this method you can't
use template / generic parameters.

VC++ 2005 Express Edition, can be downloaded from Microsoft.

Hope that helps,
Andre
Jan 16 '07 #4
Amu

Andre Kaufmann wrote:
Amu wrote:
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

Hi,

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.
You can use generics and map them to the associated template class.
Though generics are more restricted than templates, so you possibly
can't directly wrap the template classes by using generics.

Another solution would be wrapping the template classes in COM
interfaces or by using flat functions. Surely with this method you can't
use template / generic parameters.

VC++ 2005 Express Edition, can be downloaded from Microsoft.

Hope that helps,
Andre


The C++ classes which I mentioned are classes which are derived from
MFC standard classes like CPropertyPage and CPropertySheet.

These template classes are simple MFC classes which are packaged as a
DLL. Since the Implementation part of this DLL is huge, I can't think
of rewriting the whole code in C#.

I have attached the the class template code snippet for your reference.
I need to inherit from this class, DTMPOPropertyPa ge in C#.

How can I achieve this?

class AFX_EXT_CLASS DTMPOPropertyPa ge : public CPropertyPage

{

// Construction

public:

//DECLARE_DYNAMIC (DTMPOPropertyP age)

DTMPOPropertyPa ge(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);

~DTMPOPropertyP age();

//{{AFX_DATA(CXmt rPropertyPage)

// NOTE - ClassWizard will add data members
here.

// DO NOT EDIT what you see in these blocks
of generated code !

//}}AFX_DATA

// Attributes

public:

// Access to determine if performing CANCEL processing.

// Pages use this to avoid validation

//BOOL InCancelProcess ing ();

// Overrides

// ClassWizard generate virtual function overrides

//{{AFX_VIRTUAL(C XmtrPropertyPag e)

// Define a generic OnKillFocus handler for use by all
pages

//afx_msg void OnKillFocus();

virtual void DoDataExchange( CDataExchange* pDX); //
DDX/DDV support

//}}AFX_VIRTUAL

virtual BOOL OnInitDialog() { return
CPropertyPage:: OnInitDialog(); }

virtual BOOL OnSetActive() { UpdateData(FALS E); return
CPropertyPage:: OnSetActive(); }

//virtual BOOL OnKillActive();

// access to BO parameters

virtual void SetValues() = 0;

virtual void UpdateDocument( ) = 0;

// access to AppInfo

FDTAppInfo *GetAppInfo();

// Implementation

protected:

// Generated message map functions

//{{AFX_MSG(CXmtr PropertyPage)

// NOTE: the ClassWizard will add member
functions here

//}}AFX_MSG

//afx_msg LRESULT OnCommandHelp(W PARAM, LPARAM lParam);

//afx_msg LRESULT OnShiftF1Help(W PARAM, LPARAM lParam);

//afx_msg void OnHelp( );

afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );

//_DLLPROC DECLARE_MESSAGE _MAP()

DTMPOPropertySh eet *GetSheet();

// pointer to document

FDTXmtrDoc *mDoc;

private:

void SetSheet( DTMPOPropertySh eet *ps );

friend class DTMPOPropertySh eet;

mDTMPOPropertyP age *m;

};

Jan 17 '07 #5
Amu

Andre Kaufmann wrote:
Amu wrote:
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

Hi,

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.
You can use generics and map them to the associated template class.
Though generics are more restricted than templates, so you possibly
can't directly wrap the template classes by using generics.

Another solution would be wrapping the template classes in COM
interfaces or by using flat functions. Surely with this method you can't
use template / generic parameters.

VC++ 2005 Express Edition, can be downloaded from Microsoft.

Hope that helps,
Andre
The C++ classes which I mentioned are classes which are derived from
MFC standard classes like CPropertyPage and CPropertySheet.

These template classes are simple MFC classes which are packaged as a
DLL. Since the Implementation part of this DLL is huge, I can't think
of rewriting the whole code in C#.

I have attached the the class template code snippet for your reference.
I need to inherit from this class, DTMPOPropertyPa ge in C#.

How can I achieve this?

class AFX_EXT_CLASS DTMPOPropertyPa ge : public CPropertyPage

{

// Construction

public:

//DECLARE_DYNAMIC (DTMPOPropertyP age)

DTMPOPropertyPa ge(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);

~DTMPOPropertyP age();

//{{AFX_DATA(CXmt rPropertyPage)

// NOTE - ClassWizard will add data members
here.

// DO NOT EDIT what you see in these blocks
of generated code !

//}}AFX_DATA

// Attributes

public:

// Access to determine if performing CANCEL processing.

// Pages use this to avoid validation

//BOOL InCancelProcess ing ();

// Overrides

// ClassWizard generate virtual function overrides

//{{AFX_VIRTUAL(C XmtrPropertyPag e)

// Define a generic OnKillFocus handler for use by all
pages

//afx_msg void OnKillFocus();

virtual void DoDataExchange( CDataExchange* pDX); //
DDX/DDV support

//}}AFX_VIRTUAL

virtual BOOL OnInitDialog() { return
CPropertyPage:: OnInitDialog(); }

virtual BOOL OnSetActive() { UpdateData(FALS E); return
CPropertyPage:: OnSetActive(); }

//virtual BOOL OnKillActive();

// access to BO parameters

virtual void SetValues() = 0;

virtual void UpdateDocument( ) = 0;

// access to AppInfo

FDTAppInfo *GetAppInfo();

// Implementation

protected:

// Generated message map functions

//{{AFX_MSG(CXmtr PropertyPage)

// NOTE: the ClassWizard will add member
functions here

//}}AFX_MSG

//afx_msg LRESULT OnCommandHelp(W PARAM, LPARAM lParam);

//afx_msg LRESULT OnShiftF1Help(W PARAM, LPARAM lParam);

//afx_msg void OnHelp( );

afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );

//_DLLPROC DECLARE_MESSAGE _MAP()

DTMPOPropertySh eet *GetSheet();

// pointer to document

FDTXmtrDoc *mDoc;

private:

void SetSheet( DTMPOPropertySh eet *ps );

friend class DTMPOPropertySh eet;

mDTMPOPropertyP age *m;

};

Jan 17 '07 #6
Amu a écrit :
Andre Kaufmann wrote:
>Amu wrote:
>>Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.

The C++ classes which I mentioned are classes which are derived from
MFC standard classes like CPropertyPage and CPropertySheet.

These template classes are simple MFC classes which are packaged as a
DLL. Since the Implementation part of this DLL is huge, I can't think
of rewriting the whole code in C#.

I have attached the the class template code snippet for your reference.
I need to inherit from this class, DTMPOPropertyPa ge in C#.

How can I achieve this?

class AFX_EXT_CLASS DTMPOPropertyPa ge : public CPropertyPage

{
// Construction
public:
//DECLARE_DYNAMIC (DTMPOPropertyP age)
DTMPOPropertyPa ge(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);
~DTMPOPropertyP age();
//{{AFX_DATA(CXmt rPropertyPage)
// NOTE - ClassWizard will add data members
here.
// DO NOT EDIT what you see in these blocks
of generated code !
//}}AFX_DATA

// Attributes
public:
// Access to determine if performing CANCEL processing.
// Pages use this to avoid validation
//BOOL InCancelProcess ing ();
// Overrides
// ClassWizard generate virtual function overrides
//{{AFX_VIRTUAL(C XmtrPropertyPag e)
// Define a generic OnKillFocus handler for use by all
pages
//afx_msg void OnKillFocus();
virtual void DoDataExchange( CDataExchange* pDX); //
DDX/DDV support
//}}AFX_VIRTUAL
virtual BOOL OnInitDialog() { return
CPropertyPage:: OnInitDialog(); }
virtual BOOL OnSetActive() { UpdateData(FALS E); return
CPropertyPage:: OnSetActive(); }
//virtual BOOL OnKillActive();
// access to BO parameters
virtual void SetValues() = 0;
virtual void UpdateDocument( ) = 0;
// access to AppInfo
FDTAppInfo *GetAppInfo();
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CXmtr PropertyPage)
// NOTE: the ClassWizard will add member
functions here
//}}AFX_MSG
//afx_msg LRESULT OnCommandHelp(W PARAM, LPARAM lParam);
//afx_msg LRESULT OnShiftF1Help(W PARAM, LPARAM lParam);
//afx_msg void OnHelp( );
afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );
//_DLLPROC DECLARE_MESSAGE _MAP()
DTMPOPropertySh eet *GetSheet();
// pointer to document
FDTXmtrDoc *mDoc;
private:
void SetSheet( DTMPOPropertySh eet *ps );
friend class DTMPOPropertySh eet;
mDTMPOPropertyP age *m;
};
I am sorry to write that you will have to forget about inheriting from
this class.
I'm far from being fluent in Managed C++, so I redirect you to these
resources about implementing a wrapper (i.e. a class that uses
composition) :
http://www.ondotnet.com/pub/a/dotnet...cpp_part3.html
http://www.codeguru.com/Cpp/Cpp/cpp_...cle.php/c6867/

Mathieu
Jan 17 '07 #7
Amu wrote:
Andre Kaufmann wrote:
>Amu wrote:
[...]
I have attached the the class template code snippet for your reference.
I need to inherit from this class, DTMPOPropertyPa ge in C#.

How can I achieve this?
As some posters already have mentioned, you can't derive directly from a
native C++ class in C#. You can wrap the class in a managed one and
embed the native class in the managed as a pointer. Directly embedding,
meaning mixing managed and native classes is not (yet) possible.

A short example gives you the idea:

(Create for example a class library in VC++ 2005,
or a CLR console application for testing):
using namespace System;

// Native C++ class - that's for example your DTMPOPropertyPa ge class
class Native
{
public: void Method() {}
};

// You can create and inherit from this class in C#
// It's a managed class and should be visible in a C#
// project if you add a reference to the DLL.
public ref class Managed
{
public:

Managed() { native = new Native(); }
~Managed() { delete native; }

// Function callable from C#
void External() { native->Method(); }

private:
Native* native;
};
[...]
Anyways mixing MFC code and C++/CLI (managed) code is not that simple,
especially if GUI components / classes are involved. There are some
examples for this type of application in the MSDN library.

You have no chance to do the above in VC6. If you must use VC6 your only
chance (IMHO) is to wrap your classes by using handles and flat
functions (just the way Win32 is doing it) and use DLLImport to call the
functions - though IMHO to much work. Or wrap your native classes in COM
objects - but IMHO quite too much work.

So you should give VC++ 2005 a try.

Andre
Jan 17 '07 #8

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

Similar topics

3
1699
by: Drew McCormack | last post by:
Does operator() get inherited? I would have thought so, but I can't get the following to work: I have a base class that takes its derived class as a template template parameter (the Barton-Nackmann trick). It has a operator() defined. template <typename NumType, template <typename T> class DerivedType> class Matrix { public:
3
1416
by: N4M | last post by:
Dear, I have codes as follows: template<class T> class A { public: // embedded class class E; public: // types typedef E TE; public:// member functions TE somefunc();
4
2955
by: Anthony Gallagher | last post by:
I have a bunch of libraries compiled using VC++ 6.0, and I am trying to recompile one of our projects using VC++ .NET. I get all kind of linker errors (specially in STL calls). How do I get rid of these errors?? Anthony
5
2343
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and run this works fine. but if build in unicode release or release this does't work. IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
12
6495
by: jarradw | last post by:
I am trying to figure out if this will work. I have a template base class that I want to be able to inherit from, the classes that will need to inherit from this also need to be tamplates. Is this possible or do i need to think of another way to do it?
1
2277
by: siva.isukapalli | last post by:
Hi, We are involved in a porting project (from VC++ 6.0 to .Net VC++ 7.1). ** NOT C# or VB..NET. We have a custom app wizard written in 6.0. This basically creates a project with a set of template based classes. We have to port it. But there is a significant change in the way custom app wizards are created in both the versions of vc++.
24
2948
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
2
1913
by: Amu | last post by:
i have a dll ( template class) ready which is written in VC++6. But presently i need to inherit its classes into my new C#.net project.so if there is some better solution with u then please give me the solution.
4
1696
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 : public virtual base
0
8585
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
9004
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7682
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
6506
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
4351
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
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3024
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
2
2288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.