Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / February 2006

Tip: Looking for answers? Try searching our database.

Unwrap returns VT_RECORD instead of VT_DISPATCH??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dnebeker - 28 Feb 2006 05:31 GMT
I have a simple managed C++ class that I want to call from unmanaged C++.  
Because of DLL Hell, etc I don't want to register it with COM (multiple apps
will use this DLL), and because of the mixed-mode deadlock/loader lock I
can't just export a function and call it (I'm using .NET 1.1).

That leaves me with the option of making a pure managed C++ assembly,
loading it into a hosted CLR, creating the object, getting an interface on it
and using it.  In theory....

The managed C++ class is literally: (functionality stripped out and still
doesn't work):

#include "stdafx.h"
#include "Charts.h"

#using <mscorlib.dll>

using namespace System;

namespace Charts
{
    class CreateChartsClass
    {
    public:
        CreateChartsClass()
        {
       
        }
    }; //class CreateCharts
} //namespace Charts

In the unmanaged code, I start the CLR, get an interface on the default app
domain, and then call:

CComPtr<_AppDomain>      gDefAppDomain;
CComPtr<_ObjectHandle>   gpChartObjectHandle;

hr = gDefAppDomain->CreateInstance(_bstr_t(L"Charts"),
_bstr_t(L"Charts.CreateChartsClass"), &gpChartObjectHandle);
//hr is S_OK here
BSTR bs = NULL;
gpChartObjectHandle->get_ToString(&bs);
//bs = "System.Runtime.Remoting.ObjectHandle"
CComVariant VntUnwrapped;
hr = gpChartObjectHandle->Unwrap(&VntUnwrapped);
//hr is S_OK here
Although Unwrap returns S_OK, the VntUnwrapped.vt value is 36 (VT_RECORD)!!!
It is supposed to be VT_DISPATCH.

What am I doing wrong?
dnebeker - 28 Feb 2006 05:40 GMT
The saga continues!  Just found that I was missing __gc on the managed C++
class.  Adding that causes Unwrap to return VT_UNKNOWN.  Not quite
VT_DISPATCH.  I tried QueryInterface for IID_IDispatch but got back
E_NOINTERFACE.  

Still can't call the function :(

> I have a simple managed C++ class that I want to call from unmanaged C++.  
> Because of DLL Hell, etc I don't want to register it with COM (multiple apps
[quoted text clipped - 46 lines]
>
> What am I doing wrong?
dnebeker - 28 Feb 2006 05:57 GMT
Getting late and I need to go to bed, but I figured it out and wanted to post
it for others' benefit.  Adding __gc to the class was close.  Adding public
__gc to the class finally let me get back a VT_DISPATCH on the object.  Now
whether I can actually call it or not, we'll see tomorrow!

> The saga continues!  Just found that I was missing __gc on the managed C++
> class.  Adding that causes Unwrap to return VT_UNKNOWN.  Not quite
[quoted text clipped - 53 lines]
> >
> > What am I doing wrong?
"Peter Huang" [MSFT] - 28 Feb 2006 07:46 GMT
Dear Customer,

Thanks for your information.
Based on my understanding, so far you can host the managed C++ in the
unmanaged C++.
If I have any misunderstanding, please feel free to post here.
I think your code will benefit the whole community about CLR hosting in
unmanaged C++, when you post back. :)

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.