المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : FilterSendMessage - talking to a MiniFilter driver



C# Programming
09-19-2009, 12:00 PM
Hi,
I'm trying to talk to a mini-filter driver using p-invoke, but cannot make this function return successfully:

C/C++ function:
HRESULT WINAPI FilterSendMessage(
IN HANDLE hPort,
IN LPVOID lpInBuffer OPTIONAL,
IN DWORD dwInBufferSize,
IN OUT LPVOID lpOutBuffer OPTIONAL,
IN DWORD dwOutBufferSize,
OUT LPDWORD lpBytesReturned
);
C# function:
[DllImport("FltLib", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
public static extern int FilterSendMessage(
[In] SafeFileHandle hPort,
[In] IntPtr lpInBuffer,
[In] int dwInBufferSize,
[In, Out] IntPtr lpOutBuffer,
[In] int dwOutBufferSize,
[Out] out int lpBytesReturned);
My problem is that whenever I call this function (in C# code) it returns 0x80070057 (Invalid parameter). The handle to the port is valid, and I have received a message from the filter just before this method is called.

I'm using it like this to send a message to the filter:


int bufferSize = Marshal.SizeOf(myBuffer);
IntPtr inBuffer = Marshal.AllocHGlobal(bufferSize);
int bytesReturned = 0;

Marshal.StructureToPtr(myBuffer, inBuffer, true);

int res = FltLib.FilterSendMessage(_hPort, inBuffer, bufferSize,
IntPtr.Zero, 0, out bytesReturned);

// res = 0x80070057

Any help appreciated, thanks...

Soren