1

This structure is define at http://msdn.microsoft.com/en-us/library/windows/hardware/ff541621%28v=vs.85%29.aspx

typedef struct _FILTER_MESSAGE_HEADER {
  ULONG     ReplyLength;
  ULONGLONG MessageId;
} FILTER_MESSAGE_HEADER, *PFILTER_MESSAGE_HEADER;

I defined it in C# code as below:

[StructLayout(LayoutKind.Sequential)]
public struct FILTER_MESSAGE_HEADER {
      public uint replyLength;
      public ulong messageId;
};

I only define FILTER_MESSAGE_HEADER in C# code, PFILTER_MESSAGE_HEADER isn't.

How should I do to define PFILTER_MESSAGE_HEADER??

P/S: I want to define PFILTER_MESSAGE_HEADER to use this struct in a function.

1 Answer 1

2

You don't have to (can't) define PFILTER_MESSAGE_HEADER. Just specify it as either out or ref as appropriate.

[DllImport("foo")]
void SomeMethod(ref FILTER_MESSAGE_HEADER lpMessageBuffer);


If you are specifically interested in FilterGetMessage, I'm not sure what if any dll it is exported from, but one possible signature would be as below:

[DllImport(fltmgr, CharSet=CharSet.Unicode, ExactSpelling=true, PreserveSig=false)]
void FilterGetMessage(
    CommunicationPortSafeHandle hPort, 
    ref FILTER_MESSAGE_HEADER lpMessageBuffer,
    uint dwMessageBufferSize,
    IntPtr lpOverlapped);

I used PreserveSig to automatically translate the HRESULT to an exception in the event of failure, the CharSet specification is defensive and results in the need for ExactSpelling. CommunicationPortSafeHandle would be a class which inherits from SafeHandleMinusOneIsInvalid based off of the documentation on FilterConnectCommunicationPort.

You would use this signature as:

FILTER_MESSAGE_HEADER header;
FilterGetMessage(hFilter, ref header, 
    Marshal.SizeOf(typeof(FILTER_MESSAGE_HEADER)), IntPtr.Zero);
Sign up to request clarification or add additional context in comments.

1 Comment

This is FilterGetMessage (msdn.microsoft.com/en-us/library/windows/hardware/…). PFILTER_MESSAGE_HEADER is its parameter's type. Following you: If I change to C#, I just use out FILTER_MESSAGE_HEADER. Is it right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.