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 / April 2006

Tip: Looking for answers? Try searching our database.

marshal 2-d arrays, structure members, and arrays of structures

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Humphrey - 11 Apr 2006 15:00 GMT
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

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.