我有一张 Black Magic Design 公司的采集卡。在相关文档中描述了 IDeckLinkVideoInputFrame
接口(interface)中的 GetBytes
方法允许直接访问视频帧的数据缓冲区。这是我的作品:
HRESULT DeckLinkDevice::VideoInputFrameArrived (/* in */ IDeckLinkVideoInputFrame* videoFrame, /* in */ IDeckLinkAudioInputPacket* audioPacket)
{
char* str1;
voidPtrToFrame = NULL;
videoFrame->GetBytes(&voidPtrToFrame);
sprintf(str1, "%p", voidPtrToFrame);
// the below line does not work.
SetDlgItemText(m_uiDelegate->GetSafeHwnd(), IDC_handytxtBox, str1);
}
我还在 DeckLinkDevice
类中定义了 voidPtrToFrame
:
class DeckLinkDevice::IDeckLinkInputCallback
{
...
void* voidPtrToFrame;
...
}
最后一行出现与str1
相关的错误:
argument of type "char*" is incompatible with parameter of type LPCWSTR
我想知道:
如何在编辑控件中显示 voidPtrToFrame
的值?即我想显示包含视频帧的缓冲区地址。在下图中,我提供了有关 GetBytes
方法的必要信息。
我在谷歌上搜索了很多并测试了几种方法。但是我无法在 MFC 中实现它们。
最佳答案
你有两个问题:
<强>1。你遇到崩溃或至少是未定义的行为
变量 str1
从未被初始化。这是一个典型的初学者错误。
问题出在这里:
char* str1;
voidPtrToFrame = NULL;
videoFrame->GetBytes(&voidPtrToFrame);
// here str1 points to an interterminate location, it has never been
// initialized !! Therefore your program most likely will crash
sprintf(str1, "%p", voidPtrToFrame)
你需要这个:
char str1[20]; //<<< changement here
voidPtrToFrame = NULL;
videoFrame->GetBytes(&voidPtrToFrame);
// now str1 points to a 20 byte buffer
sprintf(str1, "%p", voidPtrToFrame);
<强>2。必须使用宽字符
您正在为 unicode 编译,因此您需要这个(此处包含之前的其他更正):
wchar_t str1[20];
voidPtrToFrame = NULL;
videoFrame->GetBytes(&voidPtrToFrame);
wsprintf(str1, L"%p", voidPtrToFrame);
SetDlgItemText(m_uiDelegate->GetSafeHwnd(), IDC_handytxtBox, str1);
关于c++ - MFC中如何显示指针的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37028086/