圈圈.测试代码.MEMBER_PASSTHROUGH_COMPLETE
1、这是 看 圈圈 的第10章 的内容遇到的问题,主要是 类“class MyUsbLowerFilterDevice :public KWdmFilterDevice”中的 宏MEMBER_PASSTHROUGH_COMPLETE 不理解
1.1、看代码中的 注释,便于理解一些
2、测试代码:
2.1、环境:Win7x64,VS08(x86)
2.2、代码:
#include <stdio.h> #include <stdlib.h> #include <windows.h> #include <map> #include <math.h> #include <list> #include <string> #include <sstream> #include <algorithm>// std::find(...) #include <vector> using namespace std; //#include "stdafx.h" #include <iostream> #include <windows.h> #include <math.h> using namespace std; typedef long (*PIO_COMPLETION_ROUTINE) ( int _i, int _j, void* _k ); #define LinkTo(x) x##LINK //#define MEMBER_PASSTHROUGH_COMPLETE(classname, member)\ // NTSTATUS member(KIrp theIrp);\ // static NTSTATUS LinkTo(memner)(PDEVICE_OBJECT DeviceObject, PIRP TheIRP, PVOID pContext)\ // {\ // KIrp I(TheIrp);\ // return static_cast<classname*>(pContext)->member(I);\ // } #define MEMBER_PASSTHROUGH_COMPLETE(classname, member)\ long member(int _i);\ static long LinkTo(member)(int DeviceObject, int TheIRP, void* pContext)\ {\ return static_cast<classname*>(pContext)->member(TheIRP);\ } // ZC: 上面的 静态转换 “static_cast<classname*>” class CAA { public: MEMBER_PASSTHROUGH_COMPLETE(CAA, IrpCompletionRoutine); // 上面这个宏,翻译一下,实际就是下面的写法 //long IrpCompletionRoutine(int _i);// 函数声明 //// 静态函数的声明以及定义 //// 这里的“LinkTo”也是一个宏,实际作用是 获取一个函数的函数名“IrpCompletionRoutineLINK” //static long IrpCompletionRoutineLINK(int DeviceObject, int TheIRP, void* pContext) //{ // // 这里的 参数pContext,实际就是 类CAA 的对象指针 // return static_cast<CAA*>(pContext)->IrpCompletionRoutine(TheIRP); //} int cc(PIO_COMPLETION_ROUTINE _p) { return _p(1, 2, this); } int dd(int _i) { return cc(LinkTo(IrpCompletionRoutine)); } }; long CAA::IrpCompletionRoutine(int _i) { return 20; } void main() { // “class MyUsbLowerFilterDevice :public KWdmFilterDevice” 中,关于 宏MEMBER_PASSTHROUGH_COMPLETE 的使用, // 一直不理解是在干什么,这里是测试的代码,用于理解 宏MEMBER_PASSTHROUGH_COMPLETE 的含义 CAA ca; int i = ca.dd(1); printf("%d\n", i); system("pause"); }
3、
4、
5、

浙公网安备 33010602011771号