Hi everyone..
I was trying to implement callback fucntions in native codes in my
VC8 class, and referred to some online codes which use native class
nested within managed class. basically of the form,
__gc class CManagedClass
{
__nogc CNativeClass
{
//blah blah blah
};
};
I tried to replocate the same thing using C++/CLI, but failed. I force
the compiler to use /clr::oldsyntax and was able to compile with
problem. So it seems the problem only appear in VC8 and worked on VC7.
my C++/CLI equivalent of the same code is as follows,
public ref class CManagedClass
{
class CNativeClass
{
//blah blah blah
};
};
setting to value also does not work. And I need it in ref as this is a
..NET wrapper for the native codes, and it compiled into a .NET assembly.
The compilation failed with the error, C2814: A native type cannot be
nested within a managed type. So obviously, by not putting the __nogc,
it is treating the CNativeClass as a native class indeed and the
compiler is complaining about it. So, in VC8, what is the work around
for this issue? It cannot be that the change to VC8 prevents callback
mechanism from native codes to managed codes. Doing so will break many
old codes which use things like event sinks and even the win32 API
EnumWindow which is often used as an example of native callback in .NET.
Can someone please enlighten me ? 9 3109
Lonewolf wrote: Hi everyone..
I was trying to implement callback fucntions in native codes in my VC8 class, and referred to some online codes which use native class nested within managed class. basically of the form,
__gc class CManagedClass { __nogc CNativeClass { //blah blah blah }; }; [...]
Try the following:
class CNativeClass {};
ref class CManagedClass{
CNativeClass* a;
//CNativeClass a; -> fails
};
AFAIK embedding a native class is not (yet) possible. IIRC it will be
supported in the next version of VC. Meanwhile you have to create and
destroy the native objects manually.
Hope that helps.
Andre
Andre Kaufmann wrote: Lonewolf wrote:
Hi everyone..
I was trying to implement callback fucntions in native codes in my VC8 class, and referred to some online codes which use native class nested within managed class. basically of the form,
__gc class CManagedClass { __nogc CNativeClass { //blah blah blah }; }; [...]
Try the following:
class CNativeClass {}; ref class CManagedClass{ CNativeClass* a; //CNativeClass a; -> fails };
AFAIK embedding a native class is not (yet) possible. IIRC it will be supported in the next version of VC. Meanwhile you have to create and destroy the native objects manually.
Hope that helps.
Andre
hi,
thanx for taking the trouble to enlighten me. I have indeed done just
that. However, as i mentioned, this method can't work for callback
fucntions and event sinks to native class which I need to propagate to
the managed class via delegate. I knew this is possible and supported in
VC7 as I already have the code running using oldsyntax in VC8, However,
I would like to know the VC8 equivalent of this technique. It has to be
possible, otherwise, native class' event sink can never propagate to
managed side and the whole thing would be useless. You can refer to this
link to see the VC7 implementation. http://www.codeproject.com/managedcpp/cbwijw.asp
What is MS answer to this? no more callback in VC8?? it cannot be that
idiotic.
Lonewolf wrote: hi, thanx for taking the trouble to enlighten me. I have indeed done just that. However, as i mentioned, this method can't work for callback fucntions and event sinks to native class which I need to propagate to the managed class via delegate. I knew this is possible and supported in VC7 as I already have the code running using oldsyntax in VC8, However, I would like to know the VC8 equivalent of this technique. It has to be possible, otherwise, native class' event sink can never propagate to managed side and the whole thing would be useless. You can refer to this link to see the VC7 implementation. http://www.codeproject.com/managedcpp/cbwijw.asp
What is MS answer to this? no more callback in VC8?? it cannot be that idiotic.
Why require the native class to be nested? Just un-nest it and you should
be fine. You might have to make a function public that you otherwise
wouldn't have, but it should work.
It does seem like a rather pointless restriction in C++/CLI though.
Embedding a native class in a ref class is one thing (clearly not
supported), but why not support the lexical nesting? That has no runtime
significance at all since the nested class would not be visible to the CLR,
and nesting of is no consequence past compile time in the native case.
-cd
"Lonewolf" <an*******@mozilla.org> wrote in message
news:uu**************@tk2msftngp13.phx.gbl... thanx for taking the trouble to enlighten me. I have indeed done just that. However, as i mentioned, this method can't work for callback fucntions and event sinks to native class which I need to propagate to the managed class via delegate. I knew this is possible and supported in VC7 as I already have the code running using oldsyntax in VC8, However, I would like to know the VC8 equivalent of this technique. It has to be possible, otherwise, native class' event sink can never propagate to managed side and the whole thing would be useless. You can refer to this link to see the VC7 implementation. http://www.codeproject.com/managedcpp/cbwijw.asp
What is MS answer to this? no more callback in VC8?? it cannot be that idiotic.
Is this what you wanted? http://msdn2.microsoft.com/en-us/library/367eeye0.aspx
James Park wrote: Is this what you wanted?
http://msdn2.microsoft.com/en-us/library/367eeye0.aspx
Hi,
thanx for the succor. It's working now. However, I do find htis method
a lot more complicated compared to the nested native class method
allowed in VC7. Is there a reason why MS is making this breaking change?
btw, I also realize the String class behaves very differently from VC7
and VC8. I did this,
VC8
~~~~
String^ s;
int a=12;
s="This is a string displaying a number, a="+a;
Debug::Write(s);
//output >> This is a string displaying a number, a=12
VC7
~~~~
String* s;
int a=12;
s="This is a string displaying a number, a="+a; //not allowed ! why?
Debug::Write(s);
it's probably due to me not being familiar with MC++. I came from VC6
and prev experience with .NET was in C# using VS2003. Only now then I
play with VC8's C++/CLI which made things more C++ than MC did. However,
the function ptrs and delegate can be irritating when it broke.
Lonewolf wrote: Andre Kaufmann wrote: Lonewolf wrote: [...]
Try the following:
class CNativeClass {}; ref class CManagedClass{ CNativeClass* a; //CNativeClass a; -> fails }; [...] Andre
hi, thanx for taking the trouble to enlighten me. I have indeed done just that. However, as i mentioned, this method can't work for callback fucntions and event sinks to native class which I need to propagate to the managed class via delegate. [...]
Ok, I haven't dealt with member function pointers that much. When I
needed callback functions into native code I commonly used interface
pointers for that purpose. Surely they don't map to delegates directly,
as, if I understood it correctly, it could be done in managed C++ by
using a nested class declaration ?
Perhaps the restriction of nested class declaration is a side effect of
the embedded class restrictions introduced in C++/CLI.
You can read more about this issue in: http://blogs.msdn.com/branbray/archi...20/441099.aspx
Andre
Carl Daniel [VC++ MVP] wrote: It does seem like a rather pointless restriction in C++/CLI though. Embedding a native class in a ref class is one thing (clearly not supported), but why not support the lexical nesting?
The reason is accessibility. As of now, all the member functions for native
classes are implemented as global functions -- they're not really members of
the value class used to encodes the native class. Since they aren't members,
they don't have access to non-public members of the containing class.
As we build better technology, we may move towards emitting member functions
as members of the encoding class. When that happens, we'll lift the
restriction that native classes cannot nest in managed types.
Hope that helps!
--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
Bugs? Suggestions? Feedback? http://msdn.microsoft.com/productfeedback/
"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:eP**************@TK2MSFTNGP11.phx.gbl... Carl Daniel [VC++ MVP] wrote: It does seem like a rather pointless restriction in C++/CLI though. Embedding a native class in a ref class is one thing (clearly not supported), but why not support the lexical nesting?
The reason is accessibility. As of now, all the member functions for native classes are implemented as global functions -- they're not really members of the value class used to encodes the native class. Since they aren't members, they don't have access to non-public members of the containing class.
As we build better technology, we may move towards emitting member functions as members of the encoding class. When that happens, we'll lift the restriction that native classes cannot nest in managed types.
That makes sense - and I figured the answer would be something like that.
Personally, I'd rather have 'em supported but simply lacking accessibility -
afterall, the current C++ standard grants no special access to the enclosing
class to members of a nested class. Granted, the next standard (and/or next
TC) removes that oversight.
Thanks for the explanation.
-cd This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Kantowitz |
last post by:
I am trying to wrap a native-C++ DLL in managed C++, to
use in a .NET project.
The native code is compiled into a DLL, and I have created
a .def file that exports the mangled names of the...
|
by: Peter Olcott |
last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in...
|
by: Martin Zenkel |
last post by:
Dear VS Team,
using the Beta 2 of VS 2005 I've encontered the following problem.
Let's assume threre are three Dll's, one unmanaged and two managed. In the
unmanaged we put a simple unmanged...
|
by: Herby |
last post by:
Is possible to have a managed method within a Native(un-managed) class
within a \clr project?
E.g.
class myClass
{
public:
#pragma managed
void myMethod(void);
|
by: Peter Olcott |
last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html
The above link shows that C# is 450% slower on something as simple as a nested
loop....
|
by: Lonewolf |
last post by:
Hi all,
I'm having difficulties passing data back to managed class from my
native class when the data is generated from within a native thread in
the native class itself. I will give the following...
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
I have a class that is writen in unmanaged pure native C++.
This class files (h and cpp) are inserted to a managed C++ (VC++ 2005,
C++/CLI) DLL compoenet.
This DLL compoenet is used in a C#...
|
by: dogbert1793 |
last post by:
Can a ref class have a definition for a native class nested in it?
The ref class would also have a native pointer to an instance of the
nested class (which I know is ok).
|
by: Bob Altman |
last post by:
Hi all,
We have a native class modeled after the System::Exception class, and all
exceptions that we throw derive from this class. For now this class is
quite simple: just Description and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |