C++/WinRT:MCVC 不链接事件回调
C++/WinRT: MCVC doesn't linking event callback
我正在尝试在 C++ 项目中使用 Desktop Capture API。
这里是帧池的初始化:
ScreenGrabWinCaptureApi::ScreenGrabWinCaptureApi() {
//
// <neccessary stuff for d3d device and capture item creation>
//
framePool = winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::CreateFreeThreaded(d3dDevice2,
winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
2, item.Size());
framePool.FrameArrived(&ScreenGrabWinCaptureApi::OnFrameArrived);
captureSession = framePool.CreateCaptureSession(item);
captureSession.StartCapture();
}
这里是 ScreenGrabWinCaptureApi::OnFrameArrived
定义:
void
ScreenGrabWinCaptureApi::OnFrameArrived(const winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool &sender,
const winrt::Windows::Foundation::IInspectable &) {
// <some buisness logic>
}
我正在尝试构建它,代码对编译器来说似乎没问题,但是在 framePool.FrameArrived(&ScreenGrabWinCaptureApi::OnFrameArrived);
调用
时链接失败
error LNK2019: unresolved external symbol "public: __cdecl winrt::Windows::Foundation::TypedEventHandler<struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool,struct winrt::Windows::Foundation::IInspectable>::TypedEventHandler<struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool,struct winrt::Windows::Foundation::IInspectable><void (__cdecl ScreenGrabWinCaptureApi::)(struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &,struct winrt::Windows::Foundation::IInspectable const &)>(void (__cdecl ScreenGrabWinCaptureApi::)(struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &,struct winrt::Windows::Foundation::IInspectable const &))" (??$?0P8ScreenGrabWinCaptureApi@@EAAXAEBUDirect3D11CaptureFramePool@Capture@Graphics@Windows@winrt@@AEBUIInspectable@Foundation@45@@Z@?$TypedEventHandler@UDirect3D11CaptureFramePool@Capture@Graphics@Windows@winrt@@UIInspectable@Foundation@45@@Foundation@Windows@winrt@@QEAA@P8ScreenGrabWinCaptureApi@@EAAXAEBUDirect3D11CaptureFramePool@Capture@Graphics@23@AEBUIInspectable@123@@Z@Z) referenced in function "public: __cdecl ScreenGrabWinCaptureApi::ScreenGrabWinCaptureApi(void)" (??0ScreenGrabWinCaptureApi@@QEAA@XZ)
我已经尝试了所有 reinterpret/static 转换方式,用方法引用引入变量,用 clojure 替换方法,但没有任何效果。任何人都知道这是什么原因以及如何做到这一点 运行?
正如 Simon Mourier 在评论中所说,我忘记将 header 添加到 TypedEventHandler
。我的代码在插入相应的 include 后工作:
#include "winrt/Windows.Foundation.h"
我正在尝试在 C++ 项目中使用 Desktop Capture API。
这里是帧池的初始化:
ScreenGrabWinCaptureApi::ScreenGrabWinCaptureApi() {
//
// <neccessary stuff for d3d device and capture item creation>
//
framePool = winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::CreateFreeThreaded(d3dDevice2,
winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
2, item.Size());
framePool.FrameArrived(&ScreenGrabWinCaptureApi::OnFrameArrived);
captureSession = framePool.CreateCaptureSession(item);
captureSession.StartCapture();
}
这里是 ScreenGrabWinCaptureApi::OnFrameArrived
定义:
void
ScreenGrabWinCaptureApi::OnFrameArrived(const winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool &sender,
const winrt::Windows::Foundation::IInspectable &) {
// <some buisness logic>
}
我正在尝试构建它,代码对编译器来说似乎没问题,但是在 framePool.FrameArrived(&ScreenGrabWinCaptureApi::OnFrameArrived);
调用
error LNK2019: unresolved external symbol "public: __cdecl winrt::Windows::Foundation::TypedEventHandler<struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool,struct winrt::Windows::Foundation::IInspectable>::TypedEventHandler<struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool,struct winrt::Windows::Foundation::IInspectable><void (__cdecl ScreenGrabWinCaptureApi::)(struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &,struct winrt::Windows::Foundation::IInspectable const &)>(void (__cdecl ScreenGrabWinCaptureApi::)(struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &,struct winrt::Windows::Foundation::IInspectable const &))" (??$?0P8ScreenGrabWinCaptureApi@@EAAXAEBUDirect3D11CaptureFramePool@Capture@Graphics@Windows@winrt@@AEBUIInspectable@Foundation@45@@Z@?$TypedEventHandler@UDirect3D11CaptureFramePool@Capture@Graphics@Windows@winrt@@UIInspectable@Foundation@45@@Foundation@Windows@winrt@@QEAA@P8ScreenGrabWinCaptureApi@@EAAXAEBUDirect3D11CaptureFramePool@Capture@Graphics@23@AEBUIInspectable@123@@Z@Z) referenced in function "public: __cdecl ScreenGrabWinCaptureApi::ScreenGrabWinCaptureApi(void)" (??0ScreenGrabWinCaptureApi@@QEAA@XZ)
我已经尝试了所有 reinterpret/static 转换方式,用方法引用引入变量,用 clojure 替换方法,但没有任何效果。任何人都知道这是什么原因以及如何做到这一点 运行?
正如 Simon Mourier 在评论中所说,我忘记将 header 添加到 TypedEventHandler
。我的代码在插入相应的 include 后工作:
#include "winrt/Windows.Foundation.h"