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.

Marshalling WCHAR[] struct member?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Müller - 22 Jan 2005 22:09 GMT
Hi!
Perhaps somebody can help me...

I'm trying to create COM interface and struct declarations in C# to access
parts of SAPI 4.0a.

The problem is that several structs look similar to this:
typedef struct {  // srw
    DWORD  dwSize;
    DWORD  dwWordNum;
    WCHAR  szWord[ ];
} SRWORD, *PSRWORD;
where I don't know how to tell .NET how to marshal the WCHAR[].
In the case above, dwSize holds the size of the struct plus the size of
szWord rounded up to the nearest multiple of four (as specified by the docs).
Another struct is declared as
typedef struct {  // srp
    DWORD  dwSize;
    BYTE   abWords[0];
} SRPHRASE, *PSRPHRASE;

I guess using MarshalAs(UnmanagedType.LPArray, ConstSize=0 is not _really_
something that will work...

Is there a way to marshal these structs?

And when a function requires such a struct as an argument (in/out), how do I
call this function?

Any help would be greatly appreciated...

Martin Müller
Mattias Sj?gren - 23 Jan 2005 10:46 GMT
Martin,

See if this helps

http://www.dotnetinterop.com/faq/?q=VariableLengthStruct

Mattias

Signature

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

"Peter Huang" [MSFT] - 24 Jan 2005 01:31 GMT
Hi Martin,

In addition to Mattias's suggestion, I think you may also try to take a
look at the book below.

.NET and COM: The Complete Interoperability Guide by Adam Nathan
http://www.amazon.com/exec/obidos/tg/detail/-/067232170X/104-0419702-2857537
?v=glance

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


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.