Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: C++ Builder XE5: access violation on initialization of GDI+



Permlink Replies: 2 - Last Post: Oct 30, 2015 10:11 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Alex Savelov

Posts: 1
Registered: 11/30/15
C++ Builder XE5: access violation on initialization of GDI+
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2015 5:36 AM
I'm writing simple application with form in Embarcadero XE5 (C++ Builder). It uses GDI+ 1.1. With presence of function (code listed at the bottom) application exits with access violation when initializing (or deinitializing) of GDI+. What can be a reason?

Code:

#pragma hdrstop
#pragma argsused

#define GDIPVER 0x0110
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;

extern "C"
{
long int ConvertToPng8File(void* image)
{
Gdiplus::Bitmap* newimage = (Gdiplus::Bitmap*)image;
ColorPalette* pal = (ColorPalette*)malloc(sizeof(ColorPalette) + 255*sizeof(ARGB));
pal->Count = 256;
pal->Flags = 0;
Gdiplus::Bitmap::InitializePalette(pal, PaletteTypeOptimal, 256, false, newimage);
newimage->ConvertFormat(PixelFormat8bppIndexed, DitherTypeSolid, PaletteTypeOptimal,pal,0);
free(pal);
}
}

Stack:

:0000000077b9e4b4
:0000000077B9E3DB ; ntdll.dll
:000007FEFBFE9EE1 ; C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17514_none_2b24536c71ed437a\GDIPLUS.DLL
:0000000009af156f ; Winapi::Gdipobj::initialization()
:0000000009bdacb6 ; _init_exit_proc
:0000000009bdaf70 ; _wstartupd
:00000000098f23b6 ; __acrtused

Message:

First chance exception at $0000000077B9E4B4.
Exception class $C0000005 with message 'c0000005ACCESS_VIOLATION'.
Process ImageryCreator64.exe (5648)
Bruce Salzman


Posts: 56
Registered: 8/23/02
Re: C++ Builder XE5: access violation on initialization of GDI+
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2015 7:27 AM   in response to: Alex Savelov in response to: Alex Savelov
Alex Savelov wrote:

I'm writing simple application with form in Embarcadero XE5 (C++
Builder). It uses GDI+ 1.1. With presence of function (code listed at
the bottom) application exits with access violation when initializing
(or deinitializing) of GDI+. What can be a reason?

You don't show the initialization portion (GdiplusStartup).

--
Bruce
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: C++ Builder XE5: access violation on initialization of GDI+
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2015 10:11 AM   in response to: Alex Savelov in response to: Alex Savelov
Alex wrote:

I'm writing simple application with form in Embarcadero XE5 (C++
Builder). It uses GDI+ 1.1. With presence of function (code listed at
the bottom) application exits with access violation when initializing
(or deinitializing) of GDI+. What can be a reason?

Why is the code wrapped in extern "C"? Why are you passing a Bitmap* as
a void*?

This makes me wonder if this code is in an exported DLL function. If it
is, you can't safely pass a Bitmap object over the DLL boundary, unless the
DLL is the one allocating the Bitmap in the first place.

And there is no 'return' statement, but the function is declared to have
a return value.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02