The P/I function ADsBuildVarArrayStr works. When I look at the IL, no heavy
Marshal code is done. I even suspect, that a pointer is passed to the array
and that the array even not is pinned.
But when it comes to passing a string[] array through a struct, it does not
work. Are there any secrets? (I'm using .NET 2.0)
sample what I would like to pass to a win32 function
struct blah
{
int cElements;
string [] elements
}
[DllImport("Activeds.dll", SetLastError = false, CharSet = CharSet.Unicode)]
public static extern int ADsBuildVarArrayStr(//
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr)]
string[] lppPathNames,
int arrayLen,
[MarshalAs(UnmanagedType.Struct)]
out object varArray);
newarr [mscorlib]System.String
stloc.s CS$0$0000
ldloc.s CS$0$0000
ldc.i4.0
ldstr "hoi"
stelem.ref
ldloc.s CS$0$0000
: ldc.i4.1
ldstr "doei"
: stelem.ref
ldloc.s CS$0$0000
: stloc.1
ldloc.1
ldc.i4.2
ldloca.s bla
call int32 NWCNameTranslate::ADsBuildVarArrayStr(string[], int32,
object&)
Lucvdv - 18 Nov 2005 09:32 GMT
On Fri, 18 Nov 2005 01:44:14 +0100, "Egbert Nierop \(MVP for IIS\)"
<egbert_nierop@nospam.invalid> wrote:
> sample what I would like to pass to a win32 function
>
[quoted text clipped - 3 lines]
> string [] elements
> }
Egbert,
I don't know if it is supposed to work in 2.0, but I had the same problem
in VB.Net with CLR 1.1, and there I did get an exception at runtime: "Can
not marshal field xxx of type yyyy: This type can not be marshaled as a
structure field." (xxx is a string array)
see Message-ID: <mheon1l85fask6vtsrq3bnriqrflaj7jne@4ax.com>
(posted yesterday, "Marshal array in structure")
Egbert Nierop (MVP for IIS) - 20 Nov 2005 09:59 GMT
> On Fri, 18 Nov 2005 01:44:14 +0100, "Egbert Nierop \(MVP for IIS\)"
> <egbert_nierop@nospam.invalid> wrote:
[quoted text clipped - 13 lines]
> not marshal field xxx of type yyyy: This type can not be marshaled as a
> structure field." (xxx is a string array)
This might be the only reason to jump to MC++ for separate reasons.
jg - 21 Nov 2005 05:41 GMT
take a look at the thread for "passing C# array to and from C array"
try one of them by ptr and by real array. ODN't know if it work for string
at all, depending on the char encoding.
(ansi vs unicode)
>> On Fri, 18 Nov 2005 01:44:14 +0100, "Egbert Nierop \(MVP for IIS\)"
>> <egbert_nierop@nospam.invalid> wrote:
[quoted text clipped - 15 lines]
>>
> This might be the only reason to jump to MC++ for separate reasons.