473,657 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

doing some initialization before the constructor gets called

Hello,

I am working in VC++ environment.whi le 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::CT extEffect(LPUNK NOWN pUnk, HRESULT *phr)
:bitmap(L"C:\\l ogo1.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::Gdiplu sStartupInput gdiplusStartupI nput;
Gdiplus::Gdiplu sStartup(&m_gdi plusToken, &gdiplusStartup Input, 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
3 3205
> Hello,

I am working in VC++ environment.whi le 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::CT extEffect(LPUNK NOWN pUnk, HRESULT *phr)
:bitmap(L"C:\\l ogo1.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::Gdiplu sStartupInput gdiplusStartupI nput;
Gdiplus::Gdiplu sStartup(&m_gdi plusToken, &gdiplusStartup Input, 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(vo id)
{
static bool initialized = flase;

if (!initialized)
{
Gdiplus::Gdiplu sStartupInput gdiplusStartupI nput;
Gdiplus::Gdiplu sStartup(&m_gdi plusToken, &gdiplusStartup Input,
NULL);

initialized = true;
}
}

call it in all constructors needing gdiplus resources.

Regards,
Ben
Jul 23 '05 #2
Me
Vamsi wrote:
CTextEffect::CT extEffect(LPUNK NOWN pUnk, HRESULT *phr)
:bitmap(L"C:\\l ogo1.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::Gdiplu sStartupInput gdiplusStartupI nput;
Gdiplus::Gdiplu sStartup(&m_gdi plusToken, &gdiplusStartup Input, 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::Gdiplu sStartupInput gdiplusStartupI nput;
Gdiplus::Gdiplu sStartup(&m_gdi plusToken, &gdiplusStartup Input, NULL);
return 0;
}

static int dummy = dummy_init();
....
CTextEffect someProblematic GlobalTextEffec t;

Jul 23 '05 #3
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::CT extEffect(LPUNK NOWN 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2010
by: JKop | last post by:
Is this them all?: class Dummy { public: Dummy() {} Dummy(const Dummy& original) { }
17
2071
by: Thomas Lorenz | last post by:
Hello, I'm a little confused about object initialization. According to Stroustrup (The C++ Programming Language, Special Edition, Section 10.2.3) constructor arguments should be supplied in one of the following notations: MyClass instance1 = MyClass(1, 2, 3); MyClass instance2(4, 5, 6); What's curious: the second notation variant is called an "abbreviated form"
18
5431
by: Makis Papapanagiotou | last post by:
Hello all, There is a strange case where a class Test is composed from three objects of other classes. i.e. class Test { public: Test(); private: Point x;
6
2154
by: Boni | last post by:
Dear all, if I initialize member like this class A { pen _mypen= new pen(...) } and class A has 3 constructors will pen be initialized in all of them?
3
1386
by: shu | last post by:
I get a _CrtIsValidHeapPointer assertion when trying to have a unmanaged static object linked to my managed project. I have tried to reduce the problem to a very simple case: One unmanaged .cpp file (compiled with "No Common language Runtime Support") added to a managed .exe project. This unmanaged .cpp declares a static object, with its constructor and destructor.
49
2302
by: Luke Meyers | last post by:
Lately I find myself increasingly preferring the practice of going ever-so-slightly out of my way to avoid the use of the form of initialization which uses the '=' symbol, on the grounds that it can be mistaken too easily for assignment. I like the avoidance of mistakes. I like even more the frequent, subtle reinforcement (for myself and my colleagues) of the point that assignment and initialization are entirely different operations. ...
8
8922
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it. Like, for instance the Objective-C method: +(void)initialize Which has the following characteristics: It is guaranteed to be run
23
3649
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for the built-in types, the value is usually garbage. Is this right? However, I'm a bit confused about value-initialization, when does it happen, and what kind of values are assigned to objects?
4
3705
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and value-initialization. I think default-init calls default constructor for class objects and sets garbage values to PODs. Value-init also calls default constructor for class objects and sets 0s to POD types. This is what I've learned from the books (especially...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.