PC Review


Reply
Thread Tools Rate Thread

How to access a pointer to an existing structure?

 
 
Sujoan
Guest
Posts: n/a
 
      1st Apr 2006
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.

 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      1st Apr 2006
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Void pointer and structure pointer Nasif Microsoft C# .NET 3 20th Jun 2008 05:55 PM
How to access a pointer to an existing structure? Sujoan Microsoft Dot NET 0 1st Apr 2006 05:35 AM
C# P/Invoke to pass pointer-to-pointer-to-structure (**pPtr) to C =?Utf-8?B?YnJja2Nj?= Microsoft C# .NET 0 30th Nov 2004 10:29 PM
Re: Copying unmanaged memory pointer of structure to managed structure array Mattias Sjögren Microsoft VC .NET 0 28th Aug 2004 03:19 PM
Creating a table in Access based on structure of existing table Microsoft C# .NET 1 20th Dec 2003 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 PM.