Help with interface

M

Michael C

I'm trying to convert this interface over to C# but can't get any of the
functions to work at all. I'm just trying as a start to get the get_Name
function to work but can't get anything out of it that looks like a BSTR. I
don't have a full understanding of how com works on this level, I'm only
using "InterfaceIsDual" because it seems to work best. I even tried
modifying the get_Name function so that it returned strName as an int and
just looked up the memory address but couldn't see anything in memory that
looked even vaugely like string.

Many thanks in advance. The C++ version is below and my C# version below
that.

DEFINE_GUID(IID_IFilterInfo,0x56A868BAL,0x0AD4,0x11CE,0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70);

DECLARE_INTERFACE_(IFilterInfo, IDispatch)
{
BEGIN_INTERFACE
STDMETHOD(FindPin)(THIS_ BSTR strPinID, IDispatch * FAR* ppUnk) PURE;
STDMETHOD(get_Name)(THIS_ BSTR FAR* strName) PURE;
STDMETHOD(get_VendorInfo)(THIS_ BSTR FAR* strVendorInfo) PURE;
STDMETHOD(get_Filter)(THIS_ IUnknown * FAR* ppUnk) PURE;
STDMETHOD(get_Pins)(THIS_ IDispatch * FAR* ppUnk) PURE;
STDMETHOD(get_IsFileSource)(THIS_ long FAR* pbIsSource) PURE;
STDMETHOD(get_Filename)(THIS_ BSTR FAR* pstrFilename) PURE;
STDMETHOD(put_Filename)(THIS_ BSTR strFilename) PURE;
};

[ComVisible(true), ComImport,
Guid("56A868BA-0AD4-11CE-B03A-0020AF0BA770"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
internal interface IFilterInfo
{
[PreserveSig]
int get_Name([Out, MarshalAs(UnmanagedType.LPWStr)] out string strName);
}
 
J

Johann Blake

Michael,

Why are you even doing this? If it's a COM object as you mention, just
reference it in Visual Studio .NET and use it's methods as-is.

Best Regards
Johann Blake
 
C

Chris P. [MVP]

Michael,

Why are you even doing this? If it's a COM object as you mention, just
reference it in Visual Studio .NET and use it's methods as-is.

Because there is no type library provided for DirectShow, however there are
some easy ways to create one, or download from a 3rd party source.
 
M

Michael C

Johann Blake said:
Michael,

Why are you even doing this? If it's a COM object as you mention, just
reference it in Visual Studio .NET and use it's methods as-is.

It's neater to define the interfaces yourself I guess, it keeps it all in
the one project and give greater control. I've found the solution, I was
under the impression that the functions I defined in my interface could be
in any order which was not correct. I thought I was calling the function
get_Name when I was actually calling FindPin with the parameters of
get_Name!
 
M

Michael C

Chris P. said:
Because there is no type library provided for DirectShow, however there
are
some easy ways to create one, or download from a 3rd party source.

If you reference quartz.dll from within visual studio you'd only get the
classes that are exposed for use with visual basic, which is a fairly
limited implementation I believe. I'm not sure if they way I'm doing it is
the easiest way but I'm getting a much fuller understanding and now I've got
most of the problems sorted out progress is good enough. Possibly it would
have been easier to create a .net usercontrol in C++ and put all of the
functionality in there but I'm not that crash hot with C.

Michael
 
C

Chris P. [MVP]

If you reference quartz.dll from within visual studio you'd only get the
classes that are exposed for use with visual basic, which is a fairly
limited implementation I believe. I'm not sure if they way I'm doing it is
the easiest way but I'm getting a much fuller understanding and now I've got
most of the problems sorted out progress is good enough. Possibly it would
have been easier to create a .net usercontrol in C++ and put all of the
functionality in there but I'm not that crash hot with C.

You can modify the IDL's and recompile with MIDL as described here to
create a type library:
http://blogs.msdn.com/ericgu/archive/2004/09/20/232027.aspx

Did you find the type library here?
http://www.kohsuke.org/dotnet/directshowTypelib/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with imported callback to C# 3
com interop 2

Top