Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to convert FilterGetMessage from c to c#. The client that I've developed in c is working fine but as I run this code after converting it in c# it is giving me an error output as : -2147023899 please help me out for this problem.
C#
[DllImport("FltLib", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
           private static extern int <small>FilterGetMessage</small>(
                IntPtr hPort,
               IntPtr lpMessageBuffer,
               int dwMessageBufferSize,
               ref OVERLAPPED lpOverlapped);


C#
public struct OVERLAPPED {
    public UIntPtr Internal;
    public UIntPtr InternalHigh;

        public uint Offset;
        public uint OffsetHigh;
        public IntPtr Pointer;

    public IntPtr hEvent;
}
   OVERLAPPED povlp;
  povlp.Internal = UIntPtr.Zero;
             povlp.InternalHigh = UIntPtr.Zero;
             povlp.Offset = 0;
             povlp.OffsetHigh = 0;
             povlp.Pointer = IntPtr.Zero;
             povlp.hEvent = IntPtr.Zero;
             headerSize = Marshal.SizeOf(msg.MessageHeader);

                 msgsize += headerSize;
                 status = FilterGetMessage(
                     portPtr,
                     buf,
                     msgsize,
                     ref povlp);


C#

Posted
Updated 3-May-15 19:30pm
v2

1 solution

Use CharSet = CharSet.Ansi to clarify what you are doing, but i wont be the solution. The FilterGetMessage documentation says that you need to provide a FILTER_MESSAGE_HEADER structure.

Consider writing the FilterGetMessage stuff completly in a C-dll. It could be easier and write a callback for resulting data.
 
Share this answer
 
Comments
Member 11460356 4-May-15 2:39am    
Thanks for your reply can you please come up with a sample code??
Member 11460356 4-May-15 8:56am    
I did tried using converting all stuff in dll and invoke that dll into c# program actually it won't work fine because we are dealing with a driver client and a frequent request of get and send message will be there so it will only be a good practice to include it in project by converting it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900