From: Giovanni Dicanio on
"Peter Olcott" <NoSpam(a)OCR4Screen.com> ha scritto nel messaggio
news:rfKdndhqLPufrhHWnZ2dnUVZ_vOdnZ2d(a)giganews.com...

> Now I have the problem simplified down to this command line code sample
> will not compile:
> http://msdn.microsoft.com/en-us/library/ms533837(VS.85).aspx
> I am getting a bunch of link errors, here is one of them:
>
> gdipng.obj : error LNK2019: unresolved external symbol _GdipFree@4
> referenced in function "public: static void __cdecl
> Gdiplus::GdiplusBase::operator delete(void *)"

Did you link with gdiplus.lib ?

Giovanni


From: Giovanni Dicanio on
"Peter Olcott" <NoSpam(a)OCR4Screen.com> ha scritto nel messaggio
news:W7mdncFCK47CsRHWnZ2dnUVZ_v-dnZ2d(a)giganews.com...

> All of the links that I have found say they are showing you how to use
> GDI+ from C++, by they actually show you how to use GDI+ from C, not C++.

I think GDI+ is a *C++ API* (not a C API, like e.g. GDI).
I think you can't use GDI+ from pure C.

> For example they show you how to modify the WinMain() function. There is
> no WinMain() function in my MFC code.

There is a WinMain function in MFC code, but it is implemented by MFC and
not by you.

Personally, I like the MSDN approach of not using any C++ framework to show
GDI+ usage.
Why should they use MFC? Why not ATL? And what about other C++ frameworks?

If MSDN shows pure Win32 code samples, then you can adapt them in your
particular production framework, be it MFC or ATL or other...

Giovanni



From: Giovanni Dicanio on
This code compiles fine with VS2008 SP1 (note that GetEncoderClsid body is
required):

<code>

#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

#pragma comment(lib, "gdiplus.lib")


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
}

INT main()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

CLSID encoderClsid;
Status stat;
Image* image = new Image(L"Bird.bmp");

// Get the CLSID of the PNG encoder.
GetEncoderClsid(L"image/png", &encoderClsid);

stat = image->Save(L"Bird.png", &encoderClsid, NULL);

if(stat == Ok)
printf("Bird.png was saved successfully\n");
else
printf("Failure: stat = %d\n", stat);

delete image;
GdiplusShutdown(gdiplusToken);
return 0;
}

</code>


"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> ha scritto nel
messaggio news:egTZ1gYuKHA.4908(a)TK2MSFTNGP06.phx.gbl...
> "Peter Olcott" <NoSpam(a)OCR4Screen.com> ha scritto nel messaggio
> news:rfKdndhqLPufrhHWnZ2dnUVZ_vOdnZ2d(a)giganews.com...
>
>> Now I have the problem simplified down to this command line code sample
>> will not compile:
>> http://msdn.microsoft.com/en-us/library/ms533837(VS.85).aspx
>> I am getting a bunch of link errors, here is one of them:
>>
>> gdipng.obj : error LNK2019: unresolved external symbol _GdipFree@4
>> referenced in function "public: static void __cdecl
>> Gdiplus::GdiplusBase::operator delete(void *)"
>
> Did you link with gdiplus.lib ?
>
> Giovanni
>
>
From: Peter Olcott on

"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com>
wrote in message
news:egTZ1gYuKHA.4908(a)TK2MSFTNGP06.phx.gbl...
> "Peter Olcott" <NoSpam(a)OCR4Screen.com> ha scritto nel
> messaggio
> news:rfKdndhqLPufrhHWnZ2dnUVZ_vOdnZ2d(a)giganews.com...
>
>> Now I have the problem simplified down to this command
>> line code sample will not compile:
>>
>> http://msdn.microsoft.com/en-us/library/ms533837(VS.85).aspx
>> I am getting a bunch of link errors, here is one of them:
>>
>> gdipng.obj : error LNK2019: unresolved external symbol
>> _GdipFree@4 referenced in function "public: static void
>> __cdecl Gdiplus::GdiplusBase::operator delete(void *)"
>
> Did you link with gdiplus.lib ?

No, I thought that it would already know its own libraries.
Do you know the syntax for this?

cl -EHsc -O2 -linkgdiplus.lib %1.cpp
The above is one of several ways that it does not work.

>
> Giovanni
>
>


From: Peter Olcott on

"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com>
wrote in message
news:ecIoelYuKHA.732(a)TK2MSFTNGP06.phx.gbl...
> This code compiles fine with VS2008 SP1 (note that
> GetEncoderClsid body is required):

Yes, I wonder why they left that out? They should have at
least provided a link if it is not in the library.

>
> <code>
>
> #include <windows.h>
> #include <gdiplus.h>
> #include <stdio.h>
> using namespace Gdiplus;
>
> #pragma comment(lib, "gdiplus.lib")
>
>
> 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
> }
>
> INT main()
> {
> // Initialize GDI+.
> GdiplusStartupInput gdiplusStartupInput;
> ULONG_PTR gdiplusToken;
> GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,
> NULL);
>
> CLSID encoderClsid;
> Status stat;
> Image* image = new Image(L"Bird.bmp");
>
> // Get the CLSID of the PNG encoder.
> GetEncoderClsid(L"image/png", &encoderClsid);
>
> stat = image->Save(L"Bird.png", &encoderClsid, NULL);
>
> if(stat == Ok)
> printf("Bird.png was saved successfully\n");
> else
> printf("Failure: stat = %d\n", stat);
>
> delete image;
> GdiplusShutdown(gdiplusToken);
> return 0;
> }
>
> </code>
>
>
> "Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com>
> ha scritto nel messaggio
> news:egTZ1gYuKHA.4908(a)TK2MSFTNGP06.phx.gbl...
>> "Peter Olcott" <NoSpam(a)OCR4Screen.com> ha scritto nel
>> messaggio
>> news:rfKdndhqLPufrhHWnZ2dnUVZ_vOdnZ2d(a)giganews.com...
>>
>>> Now I have the problem simplified down to this command
>>> line code sample will not compile:
>>>
>>> http://msdn.microsoft.com/en-us/library/ms533837(VS.85).aspx
>>> I am getting a bunch of link errors, here is one of
>>> them:
>>>
>>> gdipng.obj : error LNK2019: unresolved external symbol
>>> _GdipFree@4 referenced in function "public: static void
>>> __cdecl Gdiplus::GdiplusBase::operator delete(void *)"
>>
>> Did you link with gdiplus.lib ?
>>
>> Giovanni
>>
>>