473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

General object wrapper

I need to wrap managed objects in unmanaged objects in a
general manner, i.e. I need a C++ COM style object that
will wrap any managed object.

I expected (optimistically) to be able to declare my class
as something like:
class GeneralObjectWrapper : public IUnknown
{
public:
GeneralObjectWrapper(System::Object wrapme);

// this method will do method calls by means of reflection
MY_RESULT bool WINAPI GenericMethodCall
(WCHAR* methodName, MY_VARIANT args[], int argcount, ...);

private:
System::Object wrapped;
}
I was hoping the C++/clr compiler would take care of the
plumbing. But - it just doesn't work. The compiler says I
can't have a managed field in an unmanaged class, which
means I'll need to create an interop wrapper. But how is
this best done?

Is there a generic wrapper class/template that I can subclass
and augment with stdcall virtuals?

I'd imagine this is how the COM interop layer creates COM
wrappers for managed objects, but it is not clear to me if
this is possible from C++.

Or is there a rock bottom C++ struct that can be registered
with the CLR as a ptr location? Would it be possible to
keep it in a MASM allocated structure? (this would save
me the expense of an extra COM style wrapper object.)

I'm not too familiar with C++ - the thing I'm trying to interface
with CLR is a MASM interpreter for a scripting language with
features that simply won't map to IL in a sensible way, and
the docs aren't tailored to this kind of project, so if someone
could give me a hint...

I realize I might be able to accomplish something similar by
using automatically generated IDispach wrappers, but I want
a more direct interface.

I'm using VS2005 pro.
Feb 20 '06 #1
2 1406
"Ole Nielsby" <ol*********@snailmail.dk> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...
I need to wrap managed objects in unmanaged objects in a
general manner, i.e. I need a C++ COM style object that
will wrap any managed object.


Then I think that you are in luck. Paul Di Lascia published a managed
wrapper class (ManWrap) here:

http://msdn.microsoft.com/msdnmag/issues/05/04/C/

If there is anything in there that you don't understand, just post again.

Regards,
Will
Feb 21 '06 #2

William DePalo [MVP VC++] <wi***********@mvps.org> wrote:
[... ] Paul Di Lascia published a managed wrapper class (ManWrap) here:

http://msdn.microsoft.com/msdnmag/issues/05/04/C/


Thanks - this clarifies the issue a lot.

As often happens, I googled for the wrong terms.

"gcroot" seems to be the magic word.

regards/Ole N.
Feb 21 '06 #3

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

Similar topics

7
by: simonwittber | last post by:
>>> gen = iterator() >>> gen.next <method-wrapper object at 0x009D1B70> >>> gen.next <method-wrapper object at 0x009D1BB0> >>> gen.next <method-wrapper object at 0x009D1B70> >>> gen.next...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
1
by: Andrew Brampton | last post by:
Hi, I'm using Boost::thread and when constructing the thread object I need to pass a Function Object so that the new thread is spawned by calling this object's operator(). So I have classes like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.