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 / January 2005

Tip: Looking for answers? Try searching our database.

Struct signature?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom Glen - 26 Jan 2005 18:59 GMT
Would someone help me figure out the signature for this struct [1]?

Thanks.

[1]
typedef struct _DATA
{
   WCHAR wzName[24];
   WCHAR wzKey[30];
   VERSION version;
   BYTE        hash[76];

} DATA, *_DATA;

enum VERSION
{
A = 1,
B = 2
};
Jared Parsons [MSFT] - 26 Jan 2005 19:31 GMT
Try

[StructLayout(LayoutKind.Sequential, Pack=4)]
public struct _Data
{
   IntPtr wzName;
   IntPtr wzKey;
   Version version;
   IntPtr hash
}

public enum Version
{
   A = 1,
   B = 2
}

Signature

Jared Parsons [MSFT]
jaredpar@online.microsoft.com
"This posting is provided "AS IS" with no warranties, and confers no rights"

> Would someone help me figure out the signature for this struct [1]?
>
[quoted text clipped - 15 lines]
>  B = 2
> };
Tom Glen - 26 Jan 2005 20:22 GMT
Thanks Jared. I hadn't anticipated a solution using IntPtr's. Doesn't this
mean I will have to mess with allocating memory and use GCHandle to make
sure it's pinned...etc?

> Try
>
[quoted text clipped - 32 lines]
>>  B = 2
>> };
Jared Parsons [MSFT] - 26 Jan 2005 21:16 GMT
I haven't done a ton of interopt but the way that I normally take care of it
is to just marshal the pointers over to strings and explicitly free the
memory in the struct.  I haven't ever had to pin any memory (or I have and
I've just gotten lucky : ) )

Jared

Signature

Jared Parsons [MSFT]
jaredpar@online.microsoft.com
"This posting is provided "AS IS" with no warranties, and confers no rights"

> Thanks Jared. I hadn't anticipated a solution using IntPtr's. Doesn't this
> mean I will have to mess with allocating memory and use GCHandle to make
[quoted text clipped - 36 lines]
> >>  B = 2
> >> };
Mattias Sj?gren - 26 Jan 2005 21:19 GMT
>Would someone help me figure out the signature for this struct [1]?

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct DATA
{
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)]
   public string wzName;
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst=30)]
   public string wzKey;
   public Version version;
   [MarshalAs(UnmanagedType.ByValArray, SizeConst=76)]
   public byte[] hash;
}

Mattias

Signature

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

Tom Glen - 26 Jan 2005 21:39 GMT
Thanks Mattias!

>>Would someone help me figure out the signature for this struct [1]?
>
[quoted text clipped - 11 lines]
>
> Mattias

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.