Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   doing some initialization before the constructor gets called (http://www.velocityreviews.com/forums/t447169-doing-some-initialization-before-the-constructor-gets-called.html)

Vamsi 07-19-2005 04:09 AM

doing some initialization before the constructor gets called
 
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


benben 07-19-2005 04:39 AM

Re: doing some initialization before the constructor gets called
 
> 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



Me 07-19-2005 04:40 AM

Re: doing some initialization before the constructor gets called
 
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;


AbdulMunaf 07-19-2005 04:46 AM

Re: doing some initialization before the constructor gets called
 
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



All times are GMT. The time now is 01:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.