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.