By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,484 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,484 IT Pros & Developers. It's quick & easy.

doing some initialization before the constructor gets called

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> 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
Jul 23 '05 #2

P: n/a
Me
Vamsi wrote:
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;

Jul 23 '05 #3

P: n/a
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

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.