Re: Can't get static SolidBrush to initialize... what am I missing
"Stick" <Stick@discussions.microsoft.com> wrote in message
news:69D19CEA-0A51-4E1B-B0F6-21D0F968329E@microsoft.com
Update:
"John Carson" wrote:
I think you have missed the point. I know that your code works fine
without static variables. That is because (assuming my diagnosis is
correct) the version of the code that doesn't use static variables
is called *after* GdiplusStartup is called, whereas the attempted
initialization of the static variables occurs *before*
GdiplusStartup is called.
Here you have definitely missed the point. What I was saying was
that you should do something like the following. First declare:
struct GDIPlusManager
{
GDIPlusManager()
{
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,
NULL); }
~GDIPlusManager()
{
Gdiplus::GdiplusShutdown(gdiplusToken);
}
private:
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
};
Ok. Well I succeeded in factoring out the GDI+ Startup stuff with a
class, and verified it worked as I can draw on my surface.
Unfortunately, this didn't fix the situation at all. Same behavior,
they remain uninitialized.
I instantiate the Gdipm like this:
Helpers::GDIPlusManager* pGdipm = new Helpers::GDIPlusManager();
a file scope level before a callback routine that the game calls which
instantiates the Cdu class (with the static brushes) once the game
reaches a state where it can do so.
Where
Helpers::GDIPlusManager* pGdipm = new Helpers::GDIPlusManager();
appears in relation to any function is irrelevant. All that matters is where
it appears in relation to your definition of the static brushes:
SolidBrush Cdu::brush_Mfd_Blk( Color(255, 0, 0, 0));
etc.
Unfortunately, I limited in that I am in a .dll, and have to
interfact to .c code. So, at this point as there is only one Cdu
instantiated anyway, I'm just going to try to use class vars to
simplify things.
I don't think use of a dll makes any difference. It is just a matter of
getting an instance of the GDIPlusManager instantiated in the *same* .cpp
file as the one that defines the static brushes and *earlier* in the file
than the definition of the static brushes.
--
John Carson