?
Solved

COM Interop

Posted on 2005-03-02
6
Medium Priority
?
382 Views
Last Modified: 2013-11-25
I'm trying to create a .net object that will provide control over a tv tuner. The problem is that when ever I try to declare a COM interface as a data member of a managed object the COM interface is also turned into a managed pointer even if the _nogc tag is used.

Is it possible to have a non managed COM interface as a memeber of a managed class and if so what might I be doing wrong?

If this can't be done are there any work arounds?

Thanks

This is what I've got so far.

public __gc class TvTuner
{
      // Constructor(s)
      TvTuner();
      // Destructor
      ~TvTuner();
      // Properties
public:
      //TODO__property void set_Channel(int channel);
      //TODO__property int get_Channel();
      __property void set_PreviewWindow(IntPtr hwnd) {m_Hwnd = hwnd;}
      //TODO__property IntPtr get_PreviewWindow();
      // Methods
public:
      static CapDeviceProp* GetCaptureDeviceProps()[];
      void SetCaptureDevice(CapDeviceProp *device);
      void Start();
private:
      HRESULT InitVideoWindow();
      HRESULT InitCaptureGraph(IMoniker *pMoniker);
      // Variables
private:
      ICaptureGraphBuilder2      __nogc*m_Build;
      IntPtr                  m_Hwnd;
                IAMTVTuner            __nogc*m_Tuner;
};
0
Comment
Question by:cdiamond66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 

Author Comment

by:cdiamond66
ID: 13533124
I guess I either asked a really difficult question or a really stupid one, but this is driving me nuts so I raised the points to try and get some one to respond.

Any way I though about trying to store the COM pointers in IntPtr structures but this doesnt seem to work either. Below is basically how I tried to do this.

// store COM pointer
IntPtr tmp = pGraph;

// retrieve COM pointer
IGraphBuilder *pGraph = reinterpret_cast<IGraphBuilder*>(tmp.ToPointer());
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 13596847
I'm not sure I understand your question fully.  Are you just trying to build a .NET Assembly that will work as a COM object?

All you need to do is declare the classes, functions, properties, etc. as public and build the thing and it *should* work.  My understanding is .NET as COM is really only fully supported in Internet Explorer.  I've been working on an ActiveX Control replacement and it's pretty nice to just build and use.

.NET creats the CCW for you when you build it this way.

How are  you instantiating the object?  You may have to register it with regasm <DLL PATH and NAME> /reg

That may be your problem.  Note that if it's a COM object you're trying to instantiate and you need a CLSID, then that's the way to at least test it.  Like I said, I'n not sure I fully understand all you're doing.

I don't think you want do to the IntPtr stuff.  If you want, you can do this: (is this C#)?

[ClassInterface(ClassInterfaceType.None)]

then for create an interface:

[InterfactType(ComInterfactType.InterfaceIsDual)]
public Interface ITVTuner
{
     void setChannel();
     void getChannel();
}

[ClassInterface(ClassInterfaceType.None)]
public class TVTuner: ITVTuner
{
   public void setChannel(etc.) {etc}
   public void getChannel(etc.) {etc}
}



0
 

Author Comment

by:cdiamond66
ID: 13821566
I came up with a solution myself. The solution was pretty simple. The problem was that becuase the pointer was declared inside a garbage collected class which made the pointer garbage collected. This made the following code fail.

comInterface->QueryInterface(IID_IBaseFilter, (void**)&gcObject);

The solution was to use a temporary non garbage collected pointer.

IBaseFilter *tmp = NULL;
comInterface->QueryInterface(IID_IBaseFilter, (void**)&tmp);
gcObject = tmp;
0
 

Accepted Solution

by:
PAQ_Man earned 0 total points
ID: 13955104
PAQed with points refunded (300)

PAQ_Man
Community Support Moderator
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question