使用 VideoPortGetProcAddress

在基于 NT 的操作系统版本上开发的视频微型端口驱动程序可以在早期操作系统版本上加载和运行,前提是微型端口驱动程序不尝试使用特定于较新操作系统版本的功能。

加载视频微型端口驱动程序时,VIDEO_PORT_CONFIG_INFO 结构的 VideoPortGetProcAddress 成员包含视频端口驱动程序导出的回调例程 VideoPortGetProcAddress 的地址。 微型端口驱动程序可以使用此回调例程来查找从videoprt.sys导出的视频端口函数 地址。 微型端口驱动程序具有函数的地址后,可以使用此地址调用函数。 以下示例代码中显示了这一点。

  // Useful typedef for a function pointer type
  //   that points to a function with same argument types
  //   as VideoPortCreateSecondaryDisplay
typedef VP_STATUS ( *pFunc(PVOID, PVOID *, ULONG));

  // Declare a pointer to a function
pFunc pVPFunction;

  // Declare a pointer to a VIDEO_PORT_CONFIG_INFO struct
PVIDEO_PORT_CONFIG_INFO pConfigInfo;

  // Call through VideoPortGetProcAddress callback
  //   to get address of VideoPortCreateSecondaryDisplay
pVPFunction = (pFunc)
  ( *(pConfigInfo->VideoPortGetProcAddress)(
                        pDeviceExt, 
                       "VideoPortCreateSecondaryDisplay")
  );
if (NULL == pVPFunction) {
  // Video port does not export the function
  ...
}
else {
  Status = pVPFunction(DevExtension, 
                      &SecondDevExtension,
                       VIDEO_DUALVIEW_REMOVABLE);
} 

通过 VideoPortGetProcAddress 回调例程执行调用后, pVPFunction 要么为 NULL ,要么包含 VideoPortCreateSecondaryDisplay 函数的地址。 如果 pVPFunctionNULL,则视频端口驱动程序不会导出你尝试查找的函数,并且微型端口驱动程序不得尝试使用它。 如果 pVPFunction 不为 NULL,则可以使用此指针调用 VideoPortCreateSecondaryDisplay ,如前面的示例所示。