Click to See Complete Forum and Search --> : Error in gdiplus.h
Xadoom
January 5th, 2006, 07:30 AM
I'm becoming mad....
My compiler gives many errors in gdiplus.h why???
This is the code (copied by MSDN)
#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>
using namespace Gdiplus;
INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid); // helper function
INT main()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
CLSID encoderClsid;
Status stat;
Image* image = new Image(L"prova.jpg");
// Get the CLSID of the PNG encoder.
GetEncoderClsid(L"image/bmp", &encoderClsid);
stat = image->Save(L"prova.bmp", &encoderClsid, NULL);
if(stat == Ok)
printf("Prova.bmp was saved successfully\n");
else
printf("Failure: stat = %d\n", stat);
delete image;
GdiplusShutdown(gdiplusToken);
return 0;
}
HELP!!! :sick:
ovidiucucu
January 5th, 2006, 07:41 AM
[ Redirected thread ]
My compiler gives many errors in gdiplus.h why???
What errors?
Xadoom
January 5th, 2006, 07:52 AM
102 errors:
Compiling...
StdAfx.cpp
d:\programmi\sdk\include\gdiplusinit.h(32) : error C2065: 'ULONG_PTR' : undeclared identifier
d:\programmi\sdk\include\gdiplusinit.h(32) : error C2065: 'token' : undeclared identifier
d:\programmi\sdk\include\gdiplusinit.h(32) : error C2165: 'left-side modifier' : cannot modify pointers to data
d:\programmi\sdk\include\gdiplusinit.h(32) : error C2071: 'NotificationHookProc' : illegal storage class
d:\programmi\sdk\include\gdiplusinit.h(33) : error C2146: syntax error : missing ')' before identifier 'token'
d:\programmi\sdk\include\gdiplusinit.h(33) : error C2165: 'left-side modifier' : cannot modify pointers to data
d:\programmi\sdk\include\gdiplusinit.h(33) : error C2071: 'NotificationUnhookProc' : illegal storage class
d:\programmi\sdk\include\gdiplusinit.h(33) : error C2059: syntax error : ')'
d:\programmi\sdk\include\gdiplusinit.h(86) : error C2059: syntax error : 'const'
....
....
...
ovidiucucu
January 5th, 2006, 08:15 AM
As a quick fix, add
typedef unsigned __int32 ULONG_PTR;
before including <gdiplus.h>
Xadoom
January 5th, 2006, 09:33 AM
I don't know how, but now i have compiled this code with Visual C++.
Now I Have a problem LInking:
--------------------Configuration: prova - Win32 Debug--------------------
Linking...
prova.obj : error LNK2001: unresolved external symbol "int __cdecl GetEncoderClsid(unsigned short const *,struct _GUID *)" (?GetEncoderClsid@@YAHPBGPAU_GUID@@@Z)
Debug/prova.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
prova.exe - 2 error(s), 0 warning(s)
I have included gdiplus.lib, what i need to include too? Help please!
Xadoom
January 5th, 2006, 09:35 AM
NOW IT WORKS!!
I have also included this function:
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
ovidiucucu
January 7th, 2006, 07:33 AM
NOW IT WORKS!!
Now you know that, no matter how much you trust in example source, need more than a simple copy/paste. ;)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.