doing some initialization before the constructor gets called

V

Vamsi

Hello,

I am working in VC++ environment.while using gdi+, i want to use a
public member variable of Bitmap. which needs to be initialized at the
time of creation. and i m using this gdi+ in a Dll application. i am
trying to initialize the bitmap object at the constructor. like

Bitmap m-bmpobj; // Bitmap Obj which is a private member of the
TextEffect Class

// TextEffect is the Class name.

CTextEffect::CTextEffect(LPUNKNOWN pUnk, HRESULT *phr)
:bitmap(L"C:\\logo1.bmp")
{
// initializing width and height mem var.
m_nWidth=0;
m_nHeight=0;

}

but the application is not initializing the bitmap with the given file.
because before using gdi+ classes we need to initialize the Gdiplus in
our application with the following two statements.

// Initializing gdi+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

So, these two statements are to processed before the constructor gets
called. But the constructor is the first function which gets called
when the dll is used.

So Please provide some tips and help to solve this problem.

Waiting for ur reply soon.

vamsi
 
B

benben

Hello,
I am working in VC++ environment.while using gdi+, i want to use a
public member variable of Bitmap. which needs to be initialized at the
time of creation. and i m using this gdi+ in a Dll application. i am
trying to initialize the bitmap object at the constructor. like

Bitmap m-bmpobj; // Bitmap Obj which is a private member of the
TextEffect Class

// TextEffect is the Class name.

CTextEffect::CTextEffect(LPUNKNOWN pUnk, HRESULT *phr)
:bitmap(L"C:\\logo1.bmp")
{
// initializing width and height mem var.
m_nWidth=0;
m_nHeight=0;

}

but the application is not initializing the bitmap with the given file.
because before using gdi+ classes we need to initialize the Gdiplus in
our application with the following two statements.

// Initializing gdi+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

So, these two statements are to processed before the constructor gets
called. But the constructor is the first function which gets called
when the dll is used.

So Please provide some tips and help to solve this problem.

Waiting for ur reply soon.

vamsi

Without considering multi-threading:

void init_gdiplus(void)
{
static bool initialized = flase;

if (!initialized)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput,
NULL);

initialized = true;
}
}

call it in all constructors needing gdiplus resources.

Regards,
Ben
 
M

Me

Vamsi said:
CTextEffect::CTextEffect(LPUNKNOWN pUnk, HRESULT *phr)
:bitmap(L"C:\\logo1.bmp")
{ ....
}

but the application is not initializing the bitmap with the given file.
because before using gdi+ classes we need to initialize the Gdiplus in
our application with the following two statements.

// Initializing gdi+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

So, these two statements are to processed before the constructor gets
called. But the constructor is the first function which gets called
when the dll is used.

So then execute those statements before the bitmap constructor gets
called. Since you told us no context about this problem, I'm guessing
you have a global variable somewhere so as a lame hack put this above
the definition of it:

int dummy_init()
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
return 0;
}

static int dummy = dummy_init();
....
CTextEffect someProblematicGlobalTextEffect;
 
A

AbdulMunaf

Call the gdi+ initialize functions in DllMain() function of dll. This
functions gets called by the Winodws when the dll is loaded in the
memory.

Or you can do the following

CTextEffect::CTextEffect(LPUNKNOWN pUnk, HRESULT *phr)
{
/*---------------------------------
gdi+ intialize code here
-----------------------------------*/
//Bitmap* m_pBitmap
m_pBitmap = new Bitmap( L"C:\\logo1.bmp" );

// initializing width and height mem var.
m_nWidth=0;
m_nHeight=0;
}

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top