简体   繁体   English

如何在MFC中显示指针的值?

[英]How to display the value of a pointer In MFC?

I have a capture card from Black Magic Design company. 我有Black Magic Design公司的采集卡。 In related document it is described that the GetBytes method, from IDeckLinkVideoInputFrame interface, allows direct access to the data buffer of a video frame. 在相关文档中描述了来自IDeckLinkVideoInputFrame接口的GetBytes方法,允许直接访问视频帧的数据缓冲区。 Here is my work: 这是我的工作:

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);
}

I also defined voidPtrToFrame in class of DeckLinkDevice : 我还在DeckLinkDevice类中定义了voidPtrToFrame

class DeckLinkDevice::IDeckLinkInputCallback
{
...
void* voidPtrToFrame;
...
}

In the last line an error appears related to str1 : 在最后一行,出现了与str1相关的错误:

argument of type "char*" is incompatible with parameter of type LPCWSTR “ char *”类型的参数与LPCWSTR类型的参数不兼容

I want to know: 我想知道:

How can I display the value of voidPtrToFrame in an Edit control? 如何在Edit控件中显示voidPtrToFrame的值? ie I want to present the address of buffer containing the video frame. 即我想提供包含视频帧的缓冲区的地址。 In the following image I provided the necessary information about GetBytes method. 在下图中,我提供了有关GetBytes方法的必要信息。

在此处输入图片说明

I googled a lot and tested several ways. 我在Google上搜索了很多,并测试了几种方法。 But I could not implement them in MFC. 但是我无法在MFC中实现它们。

You have two problems: 您有两个问题:

1. You get a crash or at least undefined behaviour 1.您遇到崩溃或至少未定义的行为

The variable str1 is never initialized. 变量str1永远不会初始化。 It's a classic beginner's error. 这是经典的初学者的错误。

The problem is here: 问题在这里:

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)

You need this: 你需要这个:

char str1[20]; //<<< changement here

voidPtrToFrame = NULL;
videoFrame->GetBytes(&voidPtrToFrame);

// now str1 points to a 20 byte buffer
sprintf(str1, "%p", voidPtrToFrame);

2. You must use wide characters 2.您必须使用宽字符

You are compiling for unicode, therefore you need this (previous other corrections are included here): 您正在为unicode进行编译,因此需要此代码(此处包含以前的其他更正):

wchar_t str1[20];

voidPtrToFrame = NULL;
videoFrame->GetBytes(&voidPtrToFrame);

wsprintf(str1, L"%p", voidPtrToFrame);
SetDlgItemText(m_uiDelegate->GetSafeHwnd(), IDC_handytxtBox, str1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM