详细查看这个位于driver.cpp文件中的入口函数会发现这个函数中主要有一个函数NdisMInitializeWrapper(
&hwrapper,
pDriverObject,
pRegistryPath,
NULL);
查看微软的帮助文档可知这个函数作用是This function notifies NDIS that a new miniport is initializing,翻译一下,函数的功能是通知NDIS这个函数是一个初始化函数,NDIS(网络驱动器标准接口),NdisMInitializeWrapper()函数是内核提供给我们的,可以直接调用。
接下来就是给
NDIS30_MINIPORT_CHARACTERISTICS这个结构体变量初始化,主要是设置一些回调函数,这是Windows程序的常见风格:
ndischar.Ndis30Chars.InitializeHandler = MiniportInitialize;
ndischar.Ndis30Chars.ResetHandler = MiniportReset;
ndischar.Ndis30Chars.CheckForHangHandler = MiniportCheckForHang;
ndischar.Ndis30Chars.HaltHandler = MiniportHalt;
ndischar.Ndis30Chars.HandleInterruptHandler = MiniportInterruptHandler;
ndischar.Ndis30Chars.ISRHandler = MiniportISRHandler;
ndischar.Ndis30Chars.QueryInformationHandler=MiniportQueryInformation;
ndischar.Ndis30Chars.SetInformationHandler = MiniportSetInformation;
ndischar.Ndis30Chars.SendHandler = MiniportSend;
很明显上面提到的通常要自己实现的。再下来就是NdisMRegisterMiniport()函数了,【F1】查看帮助文档,
This function registers an NIC or intermediate driver's Miniport_* entry points and name with the NDIS library when the driver initializes。
顾名思义这是一个注册函数,想wince内核注册驱动程序,注册刚才初始化的结构体就是用刚才初始化的那个结构体NDIS30_MINIPORT_CHARACTERISTICS注册。搞过Linux驱动的兄弟一定对这种思路一定不陌生。
函数中只有一个函数NdisTerminateWrapper,接着查看帮助文档,
This function releases system resources allocated when the NIC driver called the NdisMInitializeWrapper function,意思是说函数调用后获得系统资源。
帮助文档里有这样的描述:A miniport calls this function during initialization if it cannot find an NIC that it supports in the current platform or if it cannot successfully initialize at least one NIC or virtual NIC.那么后面将是从成功注册的结构体的第一个函数执行了即:NDIS_STATUS
MiniportInitialize(
OUT PNDIS_STATUS OpenErrorStatus,
OUT PUINT SelectedMediaIndex,
IN PNDIS_MEDIUM MediaArray,
IN UINT MediaArraySize,
IN NDIS_HANDLE MiniportHandle,
IN NDIS_HANDLE WrapperConfigHandle)
This function is a required function that sets up a network adapter, or virtual network adapter, for network I/O operations, claims all hardware resources necessary to the network adapter in the registry, and allocates resources the driver needs to carry out network I/O operations 。
意思是说,开启所有网口资源。我们看看MiniportInitialize函数中做了那些工作。
NIC_DRIVER_OBJECT *pnic;意思是实例化NIC_DRIVER_OBJECT类
附上我的注册表信息供大家参考哦!
IF BSP_DM9000 !
[HKEY_LOCAL_MACHINE/Comm/DM9CE]
"DisplayName"="DM9000A/9010 ISA Fast Ethernet Adapter"
"Group"="NDIS"
"ImagePath"="dm9isa.dll"