Convert C# 'ComImport' to VB


G

Guest

How do I accomplish the equivalent of the IFilter Runtime Callable Wrapper
(RCW) code in VB2005 or 2003, published in
http://microsoft.apress.com/asptodayarchive/74064/content-extraction-with-the-ifilter-interface? I have pasted the code down the bottom.

Basically, my problem is that the ComImport attribute cannot be used in VB
(as documented in KB313506:
http://support.microsoft.com/kb/313506/en-us?spid=7796&sid=global). I have
tried referencing query.dll, but this does not work. And I have tried the
Type Library Importer on the same dll, but it did not work.

I also don't know how to go about declaring the types such as IFILTER_INIT,
FULLPROPSPEC[] , STAT_CHUNK and FILTERREGION.

The code:

/// I can convert this bit to VB easily
[DllImport("query.dll", SetLastError=true, CharSet=CharSet.Unicode)]
private static extern int LoadIFilter(string pwcsPath,
[MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
ref IFilter ppIUnk);

/// But I cannot figure out how to convert parts of this where I say
"<--this bit":
[ComImport] <--this bit
[Guid("89BCB740-6119-101A-BCB7-00DD010655AF")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IFilter
{
void Init([MarshalAs(UnmanagedType.U4)]
IFILTER_INIT grfFlags, <--this bit
uint cAttributes,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)]
FULLPROPSPEC[] aAttributes, <--this bit
ref uint pdwFlags);

[PreserveSig]
int GetChunk(out STAT_CHUNK pStat); <--this bit

[PreserveSig]
int GetText(ref uint pcwcBuffer,
[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder buffer
);

void GetValue(ref UIntPtr ppPropValue);

void BindRegion([MarshalAs(UnmanagedType.Struct)]
FILTERREGION origPos, <--this bit
ref Guid riid,
ref UIntPtr ppunk);
}


- Thanks in advance for your assistance!
 
Ad

Advertisements

G

Guest

I have also entered this question in the more appropriate "vb.winapi" thread.
My apologies, I did not notice that thread originally.
 
Ad

Advertisements

M

Mattias Sjögren

Basically, my problem is that the ComImport attribute cannot be used in VB

That's only true for classes, the article doesn't apply for
interfaces.

/// But I cannot figure out how to convert parts of this where I say
"<--this bit":
[ComImport] <--this bit
[Guid("89BCB740-6119-101A-BCB7-00DD010655AF")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IFilter
{
void Init([MarshalAs(UnmanagedType.U4)]
IFILTER_INIT grfFlags, <--this bit
uint cAttributes,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)]
FULLPROPSPEC[] aAttributes, <--this bit
ref uint pdwFlags);

[PreserveSig]
int GetChunk(out STAT_CHUNK pStat); <--this bit

[PreserveSig]
int GetText(ref uint pcwcBuffer,
[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder buffer
);

void GetValue(ref UIntPtr ppPropValue);

void BindRegion([MarshalAs(UnmanagedType.Struct)]
FILTERREGION origPos, <--this bit
ref Guid riid,
ref UIntPtr ppunk);
}

.... , ByVal grfFlags As IFILTER_INIT, ...

.... (<Out> ByRef pStat As STAT_CHUNK)

Sub BindRegion(ByVal origPos As FILTERREGION, ...


Mattias
 

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

Top