> [PreserveSig]
> int GetText(
> [MarshalAs(UnmanagedType.U4)]
> out UInt32 pcwcBuffer,
> [MarshalAs(UnmanagedType.LPWStr)]
> out string awcBuffer
> );
Just looking at the docs for IFilter::GetText your interface is a little
off.
pcwcBuffer is not out, but is in/out. In other words it is ref.
Also note that awcBuffer is not a zero terminated string. It is just a
buffer. You might use a Char[] array instead of a String.
Setup your interface like so:
[PreserveSig]
Int32 GetText(ref UInt32 pcwcBuffer,
[MarshalAs(Unmanaged.LPArray, SizeParamIndex = 0)]
out Char[] awcBuffer)
This is untested and might not work, but it should get you closer.
If this does not work, you might try this:
Int32 GetText(ref UInt32 pcwcBuffer,
[MarshalAs(Unmanaged.LPArray, SizeConst = 1024)]
ref Char[] awcBuffer);
And then call it like this:
Char[] buff = new Char[1024];
UInt32 buffSize = 1024;
Int32 ret = MyIFilter.GetText(ref buffSize, ref buff);
You can be more precise with marshaling by using an IntPtr.
Here is an example that should definitaly work:
Int32 GetText(ref UInt32 pcwcBuffer, IntPtr awcBuffer);
And then call it like this:
Char[] data = null;
IntPtr buff = Marshal.AllocHGlobal(2048); // 1024 Chars;
try
{
Int32 buffSize = 1024; // 1024 Chars
Int32 ret = MyIFilter.GetText(ref buffSize, buff);
// You might want to do something with 'ret'
data = new Char[buffSize];
Marshal.Copy(buff, data, 0, buffSize);
}
finally
{
Marshal.FreeHGlobal(buff);
}
I will confess that I only have a few weeks of Marshaling experience in
.NET.
Hope this helps,
--
Peter
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.