How to access a pointer to an existing structure?

  • Thread starter Thread starter Sujoan
  • Start date Start date
S

Sujoan

Hi,
Iam trying to implement the QueryStatus method of IOleCommandTarget
interface.
public int QueryStatus(ref Guid pguidCmdGroup, int cCmds, IntPtr
prgCmds, IntPtr pCmdText)
{
object ocmd=Marshal.PtrToStructure(prgCmds,typeof(OLECMD));

}
Basically, prgCmds is a pointer to an existing OLECMD structure, and I
want to fill in that structure. I tried to use Marshal.PtrToStructure
to obtain the structure. But it returns an object.The structure
definition of OLECMD is as follows:
[StructLayout(LayoutKind.Sequential)]
public struct OLECMD
{
public UInt32 cmdID;
public UInt64 cmdf;
}
I want to set the value of cmdf. How to do it?Please somebody help me
in this regard.

Thanks in advance,
Sujoan.
 
Sujoan,

Please don't multipost to different groups.

public int QueryStatus(ref Guid pguidCmdGroup, int cCmds, IntPtr
prgCmds, IntPtr pCmdText)

It would be easier if you changed the signature to

public int QueryStatus(ref Guid pguidCmdGroup, int cCmds, [In, Out]
ref OLECMD prgCmds, IntPtr pCmdText)

I want to set the value of cmdf. How to do it?

OLECMD ocmd = Marshal.PtrToStructure(prgCmds,typeof(OLECMD));
ocmd.cmdf = 42;
Marshal.StructureToPtr(ocmd, prgCmds, false);


Mattias
 
Back
Top