Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

interop for string[] array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Egbert Nierop (MVP for IIS) - 18 Nov 2005 00:44 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.