Hi. I'm writing a C# front end to replace a spreadsheet/vba front end to our
legacy dcom server written in C++. I'm just learning .NET (learn by doing,
they say) and I don't really know any COM, so apologies if the answers are
obvious.
I've managed to mostly understand the process for managing dcom events, and
I've had some success figuring out how to marshal some unmanaged types to
managed. Here's one of the C++ structs that's being passed in:
typedef struct SWMArbEnvLoadStatus
{
wchar_t wcsEnvName[ 31 ];
wchar_t wcsEnvPath[ 256 ];
EWMArbLoadStatus enLoadStatus;
EWMArbError enWMArbError;
} SWMArbEnvLoadStatus;
and here's my C# struct:
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Unicode, Pack = 4 ) ]
public struct SWMArbEnvLoadStatus
{
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst = 31 ) ] // Treat the
strings as
public string wcsEnvName ; // in-place char arrays.
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst = 256 ) ]
public string wcsEnvPath ;
public WMARBENUMSLib.EWMArbLoadStatus enLoadStatus ;
public WMARBENUMSLib.EWMArbError enWMArbError ;
}
The complex structures are giving me some attitude though. Here's the meat
of some of the C++ structs that I'm required to pass in:
typedef struct SVBMarketQuoteSpreadParameters
{
...
wchar_t szRIC[ 3 ][ 20 + 1 ] ;
...
} SVBMarketQuoteSpreadParameters ;
typedef struct SVBQuoteSpreadParameters
{
SVBMarketQuoteSpreadParameters sMarketParm[ 2 ] ;
...
} SVBQuoteSpreadParameters;
typedef struct SVBInterlistedParameters
{
SVBQuoteSpreadParameters sQuoteSpreadParameters ;
...
} SVBInterlistedParameters;
There are a number of issues that I just can't figure out how to deal with:
1) In SVBInterlistedParameters, there is a structure member. How can I
marshal that as unmanaged in the same way that I might do for a string or a
float ( MarshalAs( UnmanagedType.R4 ), for example )?
2) In SVBQuoteSpreadParameters, there is a fixed-length array of structures.
How do I marshal this?
3) In SVBMarketQuoteSpreadParameters, there is a 2-D fixed length array of
char. How do I handle this?
Thanks very much for your help,
Dan
Egbert Nierop (MVP for IIS) - 11 Apr 2006 17:59 GMT
> Hi. I'm writing a C# front end to replace a spreadsheet/vba front end to
> our
[quoted text clipped - 6 lines]
> I've had some success figuring out how to marshal some unmanaged types to
> managed. Here's one of the C++ structs that's being passed in:
Hi,
You need to marshal the chararray by packing it.
here is a sample and this does it for strings. Packing a structure would be
the same concept...
http://technolog.nl/eprogrammer/archive/2005/11/24/402.aspx
> typedef struct SWMArbEnvLoadStatus
> {
[quoted text clipped - 65 lines]
> Thanks very much for your help,
> Dan