0
votes

I'm using this code to put an IplImage into a pictureBox, the commented part does not work so I0m trying with the first 3 lines of the code, but the third one returns 3 errors at compile time:
1>UIThread.obj : error LNK2028: unresolved token (0A00030D) "extern "C" struct HDC__ * stdcall GetDC(struct HWND *)" (?GetDC@@$$J14YGPAUHDC_@@PAUHWND_@@@Z) referenced in function "private: void clrcall UIThread::Form1::BtnAcquire_Click(class System::Object ^,class System::EventArgs ^)" (?BtnAcquire_Click@Form1@UIThread@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 1>UIThread.obj : error LNK2019: unresolved external symbol "extern "C" struct HDC * stdcall GetDC(struct HWND *)" (?GetDC@@$$J14YGPAUHDC_@@PAUHWND_@@@Z) referenced in function "private: void __clrcall UIThread::Form1::BtnAcquire_Click(class System::Object ^,class System::EventArgs ^)" (?BtnAcquire_Click@Form1@UIThread@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 1>C:\Users\Andrea Parola\Documents\Visual Studio 2008\Projects\UIThread\Debug\UIThread.exe : fatal error LNK1120: 2 unresolved externals

so how do I convert HWND into HDC?

            HANDLE handle = (HANDLE)this->PbBoxImg->Handle.ToInt32();
    HWND hWnd=*(HWND*)&handle;
    HDC hdc = GetDC(hWnd);
    //HDC hdc = picturebox.GetDC()->m_hDC;
    char m_chBmpBuf[2048];
    BITMAPINFO *m_pBmpInfo =0;
    m_pBmpInfo = (BITMAPINFO *)m_chBmpBuf;
    m_pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    m_pBmpInfo->bmiHeader.biWidth = img->width;
    m_pBmpInfo->bmiHeader.biHeight = -img->height;
    m_pBmpInfo->bmiHeader.biBitCount= 24;

    m_pBmpInfo->bmiHeader.biPlanes = 1;
    m_pBmpInfo->bmiHeader.biCompression = BI_RGB;
    m_pBmpInfo->bmiHeader.biSizeImage = 0;
    m_pBmpInfo->bmiHeader.biXPelsPerMeter = 0;
    m_pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
    m_pBmpInfo->bmiHeader.biClrUsed = 0;
    m_pBmpInfo->bmiHeader.biClrImportant = 0;
    StretchDIBits(hdc, 0, 0, img->width, img->height, 
                       0, 0, img->width, img->height, 
                       img->imageData, m_pBmpInfo,
                       DIB_RGB_COLORS, SRCCOPY);
1

1 Answers

2
votes

Right-click your project, Properties, Linker, Input. Delete $(NoInherit) in the Additional Dependencies setting so the linker will be told to link the standard Windows import libraries. Including user32.lib, the one that provides GetDC().

Take this as a hint that you're writing unusual code. You should be using System::Drawing in a Winforms app. StretchDIBits() is covered by Graphics::DrawImage()