|
If I write this...
Managed c++..
template<typename T>
public ref class SomeTemplate
{
public:
SomeTemplate();
void Test(void)
{
}
};
public ref class ManagedCppClassToUseFromCSharp
{
public:
SomeTemplate<System::Int32> aMember;
};
Then in c# client
ManagedCppClassToUseFromCSharp test = new ManagedCppClassToUseFromCSharp();
test does not contain a member called aMember
However if I do this...
template<typename T>
public ref class SomeTemplate
{
public:
SomeTemplate();
void Test(void)
{
}
};
public ref SomeTemplateInt : public SomeTemplate<System::Int32>
{
public:
SomeTemplateInt();
}
public ref class ManagedCppClassToUseFromCSharp
{
public:
SomeTemplateInt aMember;
};
Now I can access aMember from c#. Anyone know why and if there is a way to get around having to declare different classes derived from my template?
|
|
|
|
|
Josh, not having any direct experience myself but drawing only on memory of what I have read (whew)... since you are using C++ templates to define SomeTemplate rather than .NET generics any instance of it is a "native" type and cannot therefore be exposed through the CTS for C#.
SomeTemplate<System::Int32> aMember;
is a native member declaration NOT a managed type declaration.
led mike
|
|
|
|
|
Hello,
The template does produce a managed type as it is declared as
template<typename t="">
public ref class
{
}
the ref keyword makes it a managed type. In the second example from my original post the class derived from the template is also a managed class and the member of that type can be accessed frmo the c# client. The template must produce a managed class as you cant derive a managed class from a non-managed one.
|
|
|
|
|
Previous attempt to post this code screwed the code all up... let's try again.
namespace Library1 {
generic <typename T>
public ref class TWhat
{
T _what;
public:
property T What
{
void set(T value){ _what=value;}
T get(){ return _what;}
}
};
public ref class ManagedCppClassToUseFromCSharp
{
private:
TWhat<System::Int32>^ _twhat;
public:
ManagedCppClassToUseFromCSharp(){ _twhat = gcnew TWhat<System::Int32>(); }
TWhat<System::Int32>^ GetWhat(){return _twhat; }
};
}
and the C# code:
InitializeComponent();
Library1.ManagedCppClassToUseFromCSharp mcctuf = new ManagedCppClassToUseFromCSharp();
TWhat<System.Int32> tw = mcctuf.GetWhat();
tw.What = 11;
System.Diagnostics.Trace.WriteLine(String.Format("TWhat: {0}", tw.What));
led mike
|
|
|
|
|
Thanks mate, Ill give it a shot
|
|
|
|
|
Let me know how it goes ok?
"When your argument falls apart...resort to name-calling." Red Stateler aka (D)espeir in the Soapbox
Whereas "liberal" is just a moron. Red Stateler aka (D)espeir in the Soapbox
led mike
|
|
|
|
|
Changing the template to be a generic causes all sorts of compilation errors.
I get lots of
C3229 indirections on a generic type parameter are not allowed
C3231 template type argument cannot use a generic type parameter
This is the first few lines of the template that produce a lot of these errors
template<typename rawtype,="" typename="" managedtype="">
public ref class BoostEventAdapter
{
public:
delegate void EventDelegate(ManagedType^);
BoostEventAdapter(boost::function<void (rawtype&)=""> &boostEvent): mBoostEvent(boostEvent) {}
};
Using the template by deriving empty classes from it as I described in the first post seems to be the best way for me to go
|
|
|
|
|
How CreateDIBSection To Work For
Picture Screen On Desktop.
|
|
|
|
|
CreateDIBSection works when you call the API. If you want the desktop in a DIBSEction, you need to capture it, and copy it on to a DIBSection. That's fine, the desktop will always be a DDB, anyhow.
You've also asked this in the managed C++ forum, CreateDIBSEction is not a C++/CLI API, so this belongs in the Visual C++ forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
now,I want to learn C++/CLI, somebody would introduce a e-book for me?
(I have lern C++ before)
Thanks
|
|
|
|
|
|
|
Thanks ,and would you like to introduce a book about it to me?
|
|
|
|
|
When Nishes book is published, it will be your best bet. I say wait for it, and use web based resources in the meantime.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
How To Get All of Desktop Pixel And Copy to one variable
!=Hight Speed
|
|
|
|
|
You don't care if it's slow, is that what != High Speed means ?
Perhaps you should just search the articles, I know there's at least one on desktop capture. And in future, ask your C++ questions in the C++ forum, this is MANAGED C++.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
how i start managed C++
|
|
|
|
|
I'd say you need to know C++ first, then you buy a book, such as the excellent one that Nish will be publishing soon.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Sir,
Can u please suggest me any link that teaches how to make a web application in vc++.net.
Thanks
-- modified at 12:21 Monday 25th September, 2006
|
|
|
|
|
sir
i wanna pass an array to a fn by refrence.. The array should be allocated dynamically.. how can i it..
Can any one help me.. reply will be highly appreciated.
pls send me prototype of fn, calling fn etc. with simple eg
Thanx in advance..
shamnar
|
|
|
|
|
You're wanting to pass a managed array ? I thought that array being a class, it would have been by reference by default. Or did you mean the C++ forum ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Do u know something about link list?
|
|
|
|
|
Are you talking about a managed array? Managed arrays are a reference type so it would pass in a reference to that array.
static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) {="" y+="b;" v-="temp;" }="" while="" ((b="">>=1)>0); return y;
|
|
|
|
|
Hi all.
I'd search in the board how an can get text that is at the coordinate x,y (I have a flexgrid on external program and want to get the text of some row/column by its x,y coordinates.
I didn't found nothing. Can someone help me?
Please, help me.
Thx in advance.
Best Regards,
Marco Alves.
|
|
|
|
|
Marco2250 wrote: I didn't found nothing
I assume you mean you DID find nothing ?
This is the managed C++ forum, were you looking for a managed C++ solution, or just a C++ one ?
Either way, I've seen lots of people ask this question. I'm yet to see a full solution. If the text is in a window, then WindowFromPoint and GetWindowText are the things most likely to work.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|