|
Managed C++ runs in a virtual machine (very similar to the way java runs) and thus will most likely run slower than native code most of the time but it will provide better security and it also has built-in features that C++ does not have. A garbage collector is one of these features.
John
|
|
|
|
|
IL is compiled to native code before it
is executed. It is not like java byte code
that is interpreted.
Thank You
Bo Hunter
|
|
|
|
|
The same happens with most java virtual machines but this can in no means be as optimized as real native code because it would take much longer for to do the compile.
John
|
|
|
|
|
I'm trying to figure out how to wrap an existing (Unmanaged C++) COM Object in Managed C++ for use in .Net.
I've seen several examples both here in Code Project in MSDN. The examples I've seen so far aren't exactly the solution I've been looking for.
1) Wrap the underlying C++ Object in managed C++ and do away with COM entirely (this will probably give the best performance). This is unacceptable to the client, as they want to maintain the COM interface going forward
2) COM Interop via Managed C++, using TlbImp to import the type library from an unmanaged COM object, then including the generated METADATA inside the the client, and calling the desired interfaces.
We've already taking a crack at this, by generating the original definitons in a CLR assembly, thenediting the intermediate code/stubs to try to fix up any marshalling issues. We found our data types weren't totally compliant with automation (too complex/nested). It would require a lot of trial and error tricky editing in order to get this approach to work (if we could get it to work 100% at all).
3) Rewrite the COM Object in C#. This approach would be resource and cost prohibitive.
So the approach, we would like to take is to write a .NET wrapper, using Managed C++ on top of the COM Object. I've spent a fair amount of time searching the web and other resources for information regarding this approach. I've seen several articles referring to it, but as of yet I have not seen any (simplified) concrete examples of how to go about implementing this solution.
Is there anyone out there who is familiar with this?
A small/simple code example would get me well on the way.
Thanks in advance for your help,
JohnB
|
|
|
|
|
This is such an excellent question, I'm amazed that no one replied.
From the sound of it, you undoubtedly know alot more about this subject than I do. I've recently been reading, ".NET and COM: The Complete Interoperability Guide", by Adam Nathan. Everything I know, I learned from this book. And, I'm very new at it, but, it's a great book.
As you probably already know, the Runtime Callable Wrapper that the Type Library Importer generates is essentially what you would want to create for your COM objects. Your problem is the sheer complexity of the original DLL.
But, the obvious question is: Why must you wrap the COM objects in managed code? There really is no such thing as "pure .NET". (After all, .NET calls the underlying Win32 functions just like everything else.) I'm guessing that you will eventually want to create an application suite for the upcoming 64-bit operating system.
In Adam Nathan's book, there is a section towards the end where he describes manually defining COM types in source code. .NET compilers can produce metadata and IL, which is what the type library importer produces.
Unfortunately, I have no practical experience with this, but, I would guess it is a very time-consuming process, and the potential for systemic errors would be huge.
|
|
|
|
|
simple question, how do I make the computer beep from my managed c++ application. I've been looking a MessageBeep and Beep which both need the windows base class to work. However, I can't get either to work. Any replies would be greatly appreciated. Thanks
|
|
|
|
|
try:
#include <iostream.h>
int main()
{
cout << '\a';
}
if that's what you mean..
bye
|
|
|
|
|
I'm using the new Visual C++ Express beta and when I try to compile a file containing this code:
int fileLength = binRead->ToString()->Length;
array<Byte>^ sendFile = gcnew array<Byte>(fileLength);
I get the following errors:
error C2065: 'array' : undeclared identifier
error C2275: 'System::Byte' : illegal use of this type as an expression stdafx.cpp : see declaration of 'System::Byte'
error C2065: 'sendFile' : undeclared identifier
error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)
error C2061: syntax error : identifier 'array'
From several articles i've read it seemed to me as though I was declaring the array in the proper manner, however can anyone give me a hand with this? Could the error possibly be elsewhere in my code?
[Edit]I know when declaring native arrays the length must be a constant, is that also the case with C++/CLI Arrays?
|
|
|
|
|
BrianOlej wrote:
error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)
If the compiler does not recognize that operator it might indicate that you do not of the project configured properly for managed extensions.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I would have to have rethought my entire life if that was the problem. Naw, when I comment out the arrays the rest of the managed code compiles fine.
Signature under construction.
|
|
|
|
|
Sorry. Shot in the dark... missed everything and hit myself in the head
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
#using <System.dll>
using namespace stdcli::language;
That may help.
Thank You
Bo Hunter
|
|
|
|
|
Perfect! Thank you, it solved my problem.
Signature under construction.
|
|
|
|
|
Interesting..I thought that was automatically imported for every /clr build. Maybe not in beta 1, I guess.
Matt
|
|
|
|
|
Yeah, I thought so as well, I guess not.
Signature under construction.
|
|
|
|
|
I believe mscorlib.dll is the only
automatic import, but I have been
wrong before.
Thank You
Bo Hunter
|
|
|
|
|
How can i repair and compact a Microsoft access database with ADO.NET
Thanks
|
|
|
|
|
I don't know if that is possible. You may have to use the JET engine for those operations.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
What is the difference between Managed C++ and just plain old C++??
Also does managed having anything to do with the whole "Trusted Computing" deal M$ is trying to implement.
Mark
As you journey through life take a minute every now and then to give a thought for the other fellow.
He could be plotting something.
-Hagar the Horrible
|
|
|
|
|
|
hello,
can anyone tell me how to force an mfc window to be the parent window of an dotnet form (system.windows.form)? i want to create an modeless dotnet dialog (form) within my mfc application.
|
|
|
|
|
I'm just new to .NET, so I just plain don't know how most stuff is done.
My current problem is that I have multiple identical forms open at once. Each form has a TreeView control. These TreeViews are all supposed to display the same data, although each seperate form might have different area od the tree expanded. My problem is that if I add a node somewhere in the TreeView on one form, how do I make the TreeViews on all the other forms updated themselves with the new node, without disturbing which areas are expanded on each form.
If its useful, the data the TreeViews are displaying is stored seperately, so if I just have to rebuild the whole of each TreeView off the data I can, but of course that would mean remembering which parts of the view are expanded, mhich just sounds nasty.
Thanks
Sam
|
|
|
|
|
I more or less want to write a method that accepts a .NET string (encoded more or less in UTF-16, as I understand it) to a UTF-8 encoded string. The prototype for this method might be something like this:
Convert(String *unicodeText, char buffer[], int buflen):
The intent it to populate the buffer with a null-terminated UTF-8 encoded string logically equalivalent to the .NET string passed in as the first argument. Of course, the buflen is there to prevent overflow, although in practice it will never impose any real limitations.
I've explored the Encoder and Encoding classes offered, but as far as I can tell, they only get me to a managed array of System::Chars or System::Bytes. Perhaps I can cast a System::Byte to a (char *) or a char. Can I use Marshal::StringToXXXX to convert it to ASCII and or Unicode and then use some other functions?
Any help? I'd be extremely grateful.
Jerry
jerry@cs.stanford.edu
|
|
|
|
|
You certainly have to use System::Runtime::InteropServices::Marshal to copy memory of any kind from managed to unmanaged.
If you have already converted to UTF-8 in managed code then you should be able to marshal the memory into unmanaged buffer somehow right?
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
This is the best solution I ultimately came up with. It's not all that satisfying, because I'd think there'd be something that allowed me to do the equivalent of strcpy from a Byte[] or a char[], but if there is, then I"m unaware of it.
// Populates the specified buffer with the
// UTF-8 encoded, null-terminated C-string
// logically equivalent to the specified converts
// from a Unicode .NET string
void Convert(String *unicodeText, char buffer[], int buflen)
{
Convert(unicodeText, char buffer[], int buflen, Encoding::UTF8);
} // wrapper to a more generic function
void Convert(String *unicodeText, char buffer[], int buflen,
Encoding *encoding)
{
Byte bytes[] = encoding->GetBytes(unicodeText);
if (bytes->Count> buflen - 1) throw new Exception();
for (int i = 0; i < bytes->Count; i++)
buffer[i] = bytes[i]; // char is assignable to System::Byte
buffer[bytes->Count] = '\0';
}
A UTF-8 representation of "hello" is just like the traditional ASCII representation, since all five characters are faithfully mapped to numbers less than 128: UTF-8 and ASCII are the same. But German strings containing
umlauts and eszets, such as "FluBen" (where we'll pretend that the u is a really an umlauted u and the B is the double ess aka eszet) require more bytes. "FluBen" would marhal to 8 bytes, because the center two characters have UTF8 mappings that are two bytes wide.
If anyone knows of a more official solution to this, then I'd be delighted to hear of it. Thanks for your time.
Jerry
|
|
|
|