> Hi, I am having to write a COM wrapper dll to enable the use of a c++
> library in a c# .net app, and have a few questions regarding what
[quoted text clipped - 9 lines]
> My guess at the moment is something like:
> ULONG WindowHandle
There are plenty of ways to marshal an HWND, but the easiest and still
bit-safe way is to use a HANDLE as the native type (and cast between HWND
and HANDLE on the C++ end).
> BSTR FirstString
> BSTR SecondString
[quoted text clipped - 4 lines]
> lists right, or is there some type for representing a list of array of
> strings that contains the count?
SAFEARRAY. The IDL could look like this:
[uuid(...)]
library Test {
[object, uuid(...)]
interface ITest : IUnknown {
HRESULT Foo([in] HANDLE hwnd, [in] BSTR firstString, [in] BSTR
secondString, [out] SAFEARRAY(BSTR)* firstArray, [out] SAFEARRAY(BSTR)*
secondArray);
}
}
Put this in a type library and let tlbimp.exe do its magic, and it should
produce something that looks a lot like this without the need for any
marshalling:
void Foo(IntPtr hwnd, string firstString, string secondString, out string[]
firstArray, out string[] secondArray);
Using SAFEARRAYs in C++ is a bit of a chore, but the ATL helper clas
CComSafeArray goes a long way towards easing the pain.

Signature
J.
Oolis Kraprin - 03 Mar 2008 07:47 GMT
Thanks a lot for the reply.
I ended up with something like this:
HRESULT Address([in] ULONG windowHandle, [in] BSTR firstString, [in]
BSTR secondString, [out] VARIANT *firstArray, [out] VARIANT
*secondArray);
The ulong seems to work ok for the window handle, but I might change
it to HANDLE. I managed to specify SAFEARRAYs in the IDL but had
problems with using them in the c++ file function definition. I ended
using safearrays by wrapping them in the variants.