Click here to Skip to main content
15,894,142 members
Home / Discussions / C#
   

C#

 
Questionvoid* interop? Pin
Anonymous2-Mar-03 19:55
Anonymous2-Mar-03 19:55 
AnswerRe: void* interop? Pin
Jeff J2-Mar-03 21:16
Jeff J2-Mar-03 21:16 
GeneralRe: void* interop? Pin
Anonymous3-Mar-03 2:04
Anonymous3-Mar-03 2:04 
GeneralRe: void* interop? Pin
leppie3-Mar-03 7:06
leppie3-Mar-03 7:06 
GeneralRe: void* interop? Pin
Jeff J4-Mar-03 14:36
Jeff J4-Mar-03 14:36 
GeneralInterop - Marshaling nested structs Pin
Nathan Tran2-Mar-03 19:01
Nathan Tran2-Mar-03 19:01 
GeneralRe: Interop - Marshaling nested structs Pin
leppie3-Mar-03 7:38
leppie3-Mar-03 7:38 
GeneralRe: Interop - Marshaling nested structs Pin
Nathan Tran3-Mar-03 11:56
Nathan Tran3-Mar-03 11:56 
leppie,

I don't need the DllImportAttribute since this COM method is being called through a c# mapped interface. Based on your suggestion to use IntPtr I have made the following changes to the code but I'm still getting System.ArgumentException.

void AddDesktopItem(
[In] IntPtr component,
[In] int dwReserved
);

[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;
public int fChecked;
public int fDirty;
public int fNoScroll;
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;
public COMPSTATEINFO csiOriginal;
public COMPSTATEINFO csiRestored;
}

and the help method to copy the struct to unmanaged mem is as follows.

public static IntPtr CreateByteBuffer( COMPONENT comp )
{
IntPtr bufferPtr = Marshal.AllocCoTaskMem( Marshal.SizeOf( comp ) );
Marshal.StructureToPtr( comp, bufferPtr, true );
return bufferPtr;
}

Note: I have verified that the size of the struct to be correct. It is 8972 bytes to be exact. I have even checked the memory location of the IntPtr and all the relevant data is there.

Any other suggestion?

Nathan.

GeneralRe: Interop - Marshaling nested structs Pin
leppie4-Mar-03 7:03
leppie4-Mar-03 7:03 
GeneralHowto: image to byte array Pin
Smitha Nishant2-Mar-03 18:56
protectorSmitha Nishant2-Mar-03 18:56 
GeneralRe: Howto: image to byte array Pin
Jeff J2-Mar-03 21:26
Jeff J2-Mar-03 21:26 
GeneralRe: Howto: image to byte array Pin
Smitha Nishant2-Mar-03 22:10
protectorSmitha Nishant2-Mar-03 22:10 
General***capturing image from video*** Pin
henrykao2-Mar-03 18:37
henrykao2-Mar-03 18:37 
QuestionCan you use resources to embed a wav? Pin
jtmtv182-Mar-03 13:48
jtmtv182-Mar-03 13:48 
AnswerRe: Can you use resources to embed a wav? Pin
leppie3-Mar-03 8:02
leppie3-Mar-03 8:02 
GeneralRe: Can you use resources to embed a wav? Pin
jtmtv183-Mar-03 8:32
jtmtv183-Mar-03 8:32 
GeneralRe: Can you use resources to embed a wav? Pin
leppie4-Mar-03 6:57
leppie4-Mar-03 6:57 
GeneralAeru IRC is looking for developpers and artist Pin
Shock The Dark Mage2-Mar-03 12:46
Shock The Dark Mage2-Mar-03 12:46 
GeneralRe: Aeru IRC is looking for developpers and artist Pin
jtmtv183-Mar-03 19:17
jtmtv183-Mar-03 19:17 
GeneralRe: Aeru IRC is looking for developpers and artist Pin
Shock The Dark Mage5-Mar-03 15:47
Shock The Dark Mage5-Mar-03 15:47 
GeneralFlattening The TreeView... Pin
LokiSD2-Mar-03 10:26
LokiSD2-Mar-03 10:26 
GeneralRe: Flattening The TreeView... Pin
LokiSD3-Mar-03 7:42
LokiSD3-Mar-03 7:42 
GeneralRe: Flattening The TreeView... Pin
Furty4-Mar-03 1:49
Furty4-Mar-03 1:49 
GeneralRe: Flattening The TreeView... Pin
LokiSD5-Mar-03 6:51
LokiSD5-Mar-03 6:51 
GeneralRe: Flattening The TreeView... Pin
Furty5-Mar-03 12:06
Furty5-Mar-03 12:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.