Click here to Skip to main content
14,267,992 members

GdipDrawImage of GDI+ returns 0 ,but the picture doesn't show on my picture control

Member 11643863 asked:

Open original thread
void LoadImgFromGDIP(){
    GdiplusStartup GDIPStart = (GdiplusStartup)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdiplusStartup");
    GdipCreateFromHDC GDIPCreate = (GdipCreateFromHDC)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdipCreateFromHDC");
    GdipLoadImageFromFile GDIPLoadImgFile = (GdipLoadImageFromFile)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdipLoadImageFromFile");
    GdipDrawImageRect GDIPDrawImgRect = (GdipDrawImageRect)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdipDrawImageRect");
    GdipGetImageHeight GDIPGetImgHeight = (GdipGetImageHeight)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdipGetImageHeight");
    GdipGetImageWidth GDIPGetImgWidth = (GdipGetImageWidth)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdipGetImageWidth");
    GdipDrawImage GDIPDrawImg = (GdipDrawImage)GetProcAddress(LoadLibrary(TEXT("gdiplus.dll")), "GdipDrawImage");

    HDC hdc;
    HDC mDC;
    int lngHeight, lngWidth;
    int *img;
    int *graphics;

    GdiplusStartupInput Input;
    Input.DebugEventCallback = NULL;
    Input.GdiplusVersion = 1;
    Input.SuppressBackgroundThread = 0;
    Input.SuppressExternalCodecs = 0;
    ULONG_PTR ulToken;
    int iRet=0;
    iRet = GDIPStart(&ulToken, &Input, NULL);
    if (iRet != 0){
    hdc = BeginPaint(hPIC_LOGO, &ps);//hPIC_LOGO Handle to Picture Control
    mDC = CreateCompatibleDC(hdc);
    iRet = GDIPCreate(mDC, &graphics);
    WCHAR szFilePath[256];
    MultiByteToWideChar(CP_ACP, 0, TEXT("1.bmp"), -1, szFilePath, 256);
    iRet = GDIPLoadImgFile(szFilePath, &img);
    iRet = GDIPGetImgHeight(img, &lngHeight);
    iRet = GDIPGetImgWidth(img, &lngWidth);
    iRet = GDIPDrawImg(graphics, img, 0, 0);
    if (iRet != 0){
        MB(TEXT("ERROR,GDIPDrawImg"), 1);//MessageBox
    EndPaint(hPIC_LOGO, &ps);

I'm using plain C to call these functions of GDI+ ,and response WM_PAINT with this function ,the last call of GdipDrawImage returns 0, it means success ,but on my picture control I can not find my picture on it.
Tags: C++, C, Windows, GDI, GDI+


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100