>I need to marshal as string array in C# to an IntPtr.

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
It should be a PCWSTR "Pointer to an array of null-terminated Unicode
strings that contain the names of the attributes to retrieve for each
selected object" Here is exactly what I need this for
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/dsop_init
_info.asp
I'm trying to set the apwzAttributeNames.
Thanks,
Rodger
> Rodger,
>
[quoted text clipped - 3 lines]
>
> Mattias
Mattias Sj?gren - 05 Jan 2005 22:13 GMT
Rodger,
>It should be a PCWSTR "Pointer to an array of null-terminated Unicode
>strings that contain the names of the attributes to retrieve for each
>selected object" Here is exactly what I need this for
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/dsop_init
_info.asp
>I'm trying to set the apwzAttributeNames.
Sorry for the delay. Here's one way to do it that I think should work
int n = str.Length;
IntPtr[] stringPtrs = new IntPtr[n];
IntPtr array = Marshal.AllocHGlobal(IntPtr.Size * n);
for ( int i = 0; i < n; i++ ) {
stringPtrs[i] = Marshal.StringToHGlobalUni(str[i]);
Marshal.WriteIntPtr(array, i * IntPtr.Size, stringPtrs[i]);
}
dsop_init_info.apwzAttributeNames = array;
// call the API here
for ( int i = 0; i < n; i++ )
Marshal.FreeHGlobal(stringPtrs[i]);
Marshal.FreeHGlobal(array);
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.