🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #380

Re: C# calling Delphi-function

#380
From: Marc Rohloff TeamB
Date: Thu, 21 Apr 2005 11:14
33 lines
2161 bytes
On Thu, 21 Apr 2005 12:19:53 +0300, ttt wrote:

> I have a problem. Could somebody help me?
> I have C# program that calls a function written with Delphi.
> Why won't this structure work?
> 
> public struct UserInfo
>  {
>      public char[] FirstName;
>      public char[] LastName;
> }

What does your P/Invoke declaration look like?

In .NET arrays are reference types (pointers) and not stored in line
as they are in Delphi. You have to add some attributes to get the
runtime to Marshal them the way you need.


Commonly something like:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct UserInfo
{
     [MarshalAs(UnmanagedType.ByValArray, SizeConst=80)]
     public char[] FirstName;
     [MarshalAs(UnmanagedType.ByValArray, SizeConst=80)]
     public char[] LastName;
}


-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Technical Details
Message-ID: <1i6j144hycezq$.dlg@marcrohloff.40tude.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!transit.nntp.hccnet.nl!transit1.nntp.hccnet.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4267703a@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,e7244bf71a2c4e2c
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Marc Rohloff [TeamB]" <"on request">
Subject: Re: C# calling Delphi-function
Newsgroups: borland.public.csharpbuilder.language.csharp
User-Agent: 40tude_Dialog/2.0.15.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
References: <4267703a@newsgroups.borland.com>
Date: Thu, 21 Apr 2005 07:14:55 -0400
Message-ID: <1i6j144hycezq$.dlg@marcrohloff.40tude.net>
X-Face: "huzh55Xi]!ZNni78>a*5+).`SK?<^q2MlHk-C]Z2M9T@\J5ZCB$95Ey+s"XQuhGFA[eutZ :0^AV!Q;t>gE`1-=8d;HZ6~*o1dH<X9\b$!|(}+I'!Xq)@3Op}%0ArW&nf'Qh*EwR
X-Antivirus: avast! (VPS 0516-5, 04/20/2005), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 67.149.150.149
X-Trace: newsgroups.borland.com 1114081819 67.149.150.149 (21 Apr 2005 04:10:19 -0800)
Lines: 33
X-Authenticated-User: mrohloff
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!transit.nntp.hccnet.nl!transit1.nntp.hccnet.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail