Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Interop - Marshaling nested structs

Interop - Marshaling nested structs

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpcomhelpquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathan Tran
    wrote on last edited by
    #1

    Hi, I'm getting a System.ArgumentException trying to call the following IActiveDesktop method: STDMETHOD (AddDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE; This is how I'm marshaling the call. void AddDesktopItem( [In, MarshalAs( UnmanagedType.LPStruct )] COMPONENT pcomp, [In] int dwReserved ); I believe the problem is with marshaling the COMPONENT structure. Could some one point out to me if I'm marshaling the nested structures correctly. Here is the original typedef for the struct and my c# attempt at marshaling it. typedef struct _tagCOMPONENT { DWORD dwSize; //Size of this structure DWORD dwID; //Reserved: Set it always to zero. int iComponentType; //One of COMP_TYPE_* BOOL fChecked; // Is this component enabled? BOOL fDirty; // Had the component been modified and not BOOL fNoScroll; // Is the component scrollable? COMPPOS cpPos; // Width, height etc., WCHAR wszFriendlyName[MAX_PATH]; WCHAR wszSource[INTERNET_MAX_URL_LENGTH]; //URL of the component. WCHAR wszSubscribedURL[INTERNET_MAX_URL_LENGTH]; //Subscrined URL DWORD dwCurItemState; // Current state of the Component. COMPSTATEINFO csiOriginal; COMPSTATEINFO csiRestored; // Restored state of the component. } COMPONENT; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode )] public class COMPONENT { public int dwSize; // Size of the structure. public int dwID; // Reserved. Set to zero. public COMP_TYPE iComponentType; [MarshalAs( UnmanagedType.Bool )] public bool fChecked; [MarshalAs( UnmanagedType.Bool )] public bool fDirty; [MarshalAs( UnmanagedType.Bool )] public bool fNoScroll; [MarshalAs( UnmanagedType.Struct )] public COMPPOS cpPos; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 260 )] public string wszFriendlyName; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 2083 )] public string wszSource; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 2083 )] public string wszSubscribedURL; public ITEM_STATE dwCurItemState; [MarshalAs( UnmanagedType.Struct )] public COMPSTATEINFO csiOriginal; [MarshalAs( UnmanagedType.Struct )] public COMPSTATEINFO csiRestored; } StructLayout( LayoutKind.Sequential )] public class COMPSTATEINFO { public int dwSize; public int iLeft; public int iTop; public int dwWidth; public int dwH

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups