简体   繁体   中英

How to display the value of a pointer In MFC?

I have a capture card from Black Magic Design company. In related document it is described that the GetBytes method, from IDeckLinkVideoInputFrame interface, allows direct access to the data buffer of a video frame. 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 :

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

In the last line an error appears related to str1 :

argument of type "char*" is incompatible with parameter of type LPCWSTR

I want to know:

How can I display the value of voidPtrToFrame in an Edit control? 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.

在此处输入图片说明

I googled a lot and tested several ways. But I could not implement them in MFC.

You have two problems:

1. You get a crash or at least undefined behaviour

The variable str1 is never initialized. 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

You are compiling for unicode, therefore you need this (previous other corrections are included here):

wchar_t str1[20];

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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