使用GDI+;在C中-gdiPlusStartup函数返回2

使用GDI+;在C中-gdiPlusStartup函数返回2,c,gdi+,C,Gdi+,我试图在我的C应用程序中使用GDI+截图并将其保存为JPEG。我正在使用GDI+将BMP转换为JPEG,但显然在调用GdiplusStartup函数时,返回代码是2(无效参数),而不是0: int main() { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; //if(GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,

我试图在我的C应用程序中使用GDI+截图并将其保存为JPEG。我正在使用GDI+将BMP转换为JPEG,但显然在调用GdiplusStartup函数时,返回代码是2(无效参数),而不是0:

int main()
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    //if(GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != 0)
    //    printf("GDI NOT WORKING\n");
    printf("%d",GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL));
    HDC hdc = GetDC(NULL); // get the desktop device context
    HDC hDest = CreateCompatibleDC(hdc); // create a device context to use yourself
    // get the height and width of the screen
    int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
    int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);

    // create a bitmap
    HBITMAP hbDesktop = CreateCompatibleBitmap( hdc, width, height);

    // use the previously created device context with the bitmap
    SelectObject(hDest, hbDesktop);

    // copy from the desktop device context to the bitmap device context
    // call this once per 'frame'
    BitBlt(hDest, 0,0, width, height, hdc, 0, 0, SRCCOPY);

    // after the recording is done, release the desktop context you got..
    ReleaseDC(NULL, hdc);

    // ..and delete the context you created
    DeleteDC(hDest);
    SaveJpeg(hbDesktop,"a.jpeg",100);
    GdiplusShutdown(gdiplusToken);
    return 0;
}
我试图弄明白为什么GdiplusStartup函数不起作用。 有什么想法吗

// As Global
ULONG_PTR gdiplusToken;     

// In top of main
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&programInfo.gdiplusToken, &gdiplusStartupInput, NULL);

适用于我。

使用以下值初始化
gdiplusStartupInput
变量:
GdiplusVersion=1,DebugEventCallback=NULL,SuppressBackgroundThread=FALSE,SuppressExternalCodecs=FALSE

根据MSDN文章
GdiplusStartup function

GdiplusStartupInput
结构具有默认构造函数,该构造函数使用这些值初始化结构。由于您是从C调用函数,所以构造函数不起作用,结构仍然未初始化。提供您自己的初始化代码以解决此问题