高分求教:驱动和应用程序是否可以用管道,为什么我写的代码总是返回0xc0000034
在DriverEntry函数中创建了一个线程中的初始化代码:
RtlInitUnicodeString(&ufile_name,L"\\??\\Pipe\\Test");
//KeWaitForSingleObject(&gMutex, Executive, KernelMode, FALSE, NULL);
KeWaitForSingleObject(&gMutex, Executive, KernelMode, FALSE, NULL);
InitializeObjectAttributes(
&object_attributes,
&ufile_name,
OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE,
NULL,
NULL);
status = ZwCreateFile(&m_hPipe,
GENERIC_WRITE|GENERIC_READ|SYNCHRONIZE,
&object_attributes,
&io_status,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
0,
0);
if(!NT_SUCCESS(status))
{
DebugPrint(("\n Error %d CreateFile error ",status));
}
else
{
DebugPrint(("\r\nCreateFile successed!"));
}
应用程序:
m_hPipe = CreateNamedPipe("\\\\.\\Pipe\\Test", PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE, 1, 0, 0, 1000, NULL); // 创建命名管道
if (m_hPipe == INVALID_HANDLE_VALUE)
printf("Error %d trying to CreateNamedPipe\n", GetLastError());
else
{
printf("\r\nCreateNamedPipe successed!");
}
/*buffer 1024 + 4字节的长度*/
InBuffer = (unsigned char *)malloc(1024);
if(InBuffer == NULL)
printf("\r\nerror %s",ServerDeamon);
memset(InBuffer,'\0',1024);
if (ConnectNamedPipe(m_hPipe, NULL) == FALSE) // 等待客户机的连接
{
if(ERROR_PIPE_CONNECTED != GetLastError())
{
CloseHandle(m_hPipe); // 关闭管道句柄
printf("Error %d trying to ConnectNamedPipe\n", GetLastError());
return 0;
}
}
else
{
EnterCriticalSection(&Mutex);
printf("\r\nConnectNamedPipe successed!");
LeaveCriticalSection(&Mutex);
}
高分求教,如果有兄弟也这样用过,请给些建议,如果有例子更好! 谢谢啦!
100分不够,咱可以再加,呵呵~~~