How to access a pointer to an existing structure?

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.
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top