如何将FilterGetMessage函数从c转换为c# [英] how to convert FilterGetMessage function from c to c#
本文介绍了如何将FilterGetMessage函数从c转换为c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将FilterGetMessage从c转换为c#。我在c中开发的客户端工作正常,但是当我在c#中转换后运行此代码时,它给出了一个错误输出:-2147023899请帮我解决这个问题。
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.
[DllImport("FltLib", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
private static extern int <small>FilterGetMessage</small>(
IntPtr hPort,
IntPtr lpMessageBuffer,
int dwMessageBufferSize,
ref OVERLAPPED lpOverlapped);
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);
推荐答案
使用CharSet = CharSet.Ansi来澄清你在做什么,但我不会成为解决方案。 FilterGetMessage 文档说你需要提供一个FILTER_MESSAGE_HEADER结构。
考虑在C-dll中完全编写FilterGetMessage。它可以更容易并为结果数据写回调。
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.
这篇关于如何将FilterGetMessage函数从c转换为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文