在win7中无法打开TDI连接

potian 2013-05-23 02:25:03
NTSTATUS
TdiFuncs_OpenConnection(PWSTR pTransDevName, PHANDLE pTdiHandle, PFILE_OBJECT *pFileObject)
{
NTSTATUS NtStatus = STATUS_INSUFFICIENT_RESOURCES;
UNICODE_STRING usTdiDriverNameString;
OBJECT_ATTRIBUTES oaTdiDriverNameAttributes;
IO_STATUS_BLOCK IoStatusBlock;
char DataBlob[sizeof(FILE_FULL_EA_INFORMATION) + TDI_CONNECTION_CONTEXT_LENGTH + 300] = {0};
PFILE_FULL_EA_INFORMATION pExtendedAttributesInformation = (PFILE_FULL_EA_INFORMATION)&DataBlob;
int dwEASize = 0;

/*
* Initialize the name of the device to be opened. ZwCreateFile
* takes an OBJECT_ATTRIBUTES structure as the name of the device
* to open. This is then a two step process.
*
* 1 - Create a UNICODE_STRING data structure from a unicode string.
* 2 - Create a OBJECT_ATTRIBUTES data structure from a UNICODE_STRING.
*
*/

RtlInitUnicodeString(&usTdiDriverNameString, pTransDevName);

InitializeObjectAttributes(&oaTdiDriverNameAttributes,
&usTdiDriverNameString,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);

/*
* The second step is to initialize the Extended Attributes data structure.
*
* EaName = TdiConnectionContext, 0, Your User Defined Context Data
* (Actually a pointer to it)
* EaNameLength = Length of TdiConnectionContext
* EaValueLength = Entire Length
*/
RtlCopyMemory(&pExtendedAttributesInformation->EaName, TdiConnectionContext, TDI_CONNECTION_CONTEXT_LENGTH);

pExtendedAttributesInformation->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
pExtendedAttributesInformation->EaValueLength = TDI_CONNECTION_CONTEXT_LENGTH;
/* Must be at least TDI_CONNECTION_CONTEXT_LENGTH */

dwEASize = sizeof(DataBlob);

NtStatus = ZWCreateFile(pTdiHandle,
FILE_READ_EA | FILE_WRITE_EA,
&oaTdiDriverNameAttributes,
&IoStatusBlock,
NULL,//0,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
0,
pExtendedAttributesInformation,
dwEASize
);

if (!NT_SUCCESS(NtStatus))
{
DebugPrint(("ZwCreateFile failed with status %x\n", NtStatus));
return NtStatus;
}

if(NT_SUCCESS(NtStatus))
{
NtStatus = ObReferenceObjectByHandle(*pTdiHandle,
GENERIC_READ | GENERIC_WRITE,
NULL, KernelMode,
(PVOID *)pFileObject, NULL);

DebugPrint(("TdiFuncs_OpenConnection ObReferenceObjectByHandle %x\n", NtStatus));

if(!NT_SUCCESS(NtStatus))
{
ZwClose(*pTdiHandle);
}
}

return NtStatus;
}

在winxp中ZWCreateFile这个函数返回成功
而在win7中,ZWCreateFile返回c000000d,即:无效参数
...全文
233 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
potian 2013-05-23
  • 打赏
  • 举报
回复
请问可以将TDI驱动改为WPF驱动吗? 如果可以请问要注意哪些地方.。。小弟刚接触驱动这块,不是很懂,希望能讲详细点...谢了!!!
星星眼 2013-05-23
  • 打赏
  • 举报
回复
Win7下是WFP,TDI废弃了。

21,600

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧