PhantomDoge

How do you declare an gdiplus image object as a global variable
i simply tried:
Image image(L"image.bmp");<--this is at the beginning of the file
and i get this at runtime:
An unhandled exception of type 'system.TypeInitializationExcpetion' accurred in Unknown module

thank you




Re: Visual C++ General GDI+ Image object

Ramkrishna Pawar

Are you using .NET project type Please post it in .NET related forum.




Re: Visual C++ General GDI+ Image object

PhantomDoge

^ please read the question.
and if you dont have a clue dont answer




Re: Visual C++ General GDI+ Image object

Viorel.

I think since GDI+ requires initialization (with GdiplusStartup function), which usually is done in main function, your global variable is constructed too early, when initialization was not yet done.

If this is the cause of your problem, you should find a way to initialize GDI+ before global variables are constructed. Or build your global images in main function -- after initialization of GDI+ -- using FromFile static member.

I hope this makes sense.





Re: Visual C++ General GDI+ Image object

PhantomDoge

yes it does thanks

i tried doing that, like so outside the main function.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); <-- this here

but the third like throws:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

so i changed it to:
int GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
i get:
error C2078: too many initializers

thanks





Re: Visual C++ General GDI+ Image object

Viorel.

You cannot simply move the initialization sequence to the global scope, outside a function. But you can try something like this:

Code Snippet

static Gdiplus::GdiplusStartupInput gdiplusStartupInput;

static ULONG_PTR gdiplusToken;

static void InitGdiPlus()

{

GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

// TODO: process errors

}

static bool unused = (InitGdiPlus(), false);

Gdiplus::Image image(L"c:image.bmp");

. . .

Now you should be sure the unused variable is initialized at run-time before your images. Hopefully this is guaranteed by the compiler.





Re: Visual C++ General GDI+ Image object

PhantomDoge

thanks for your help Viorel

one more thing if you can, im using transparent images i.e png with varied transparency values, at first it
draws ok but then the transparency values levels of throughout the image with each paint.
like water speading, if that makes sense.

my guess is the paint method is drawing over and over the same image, so tranparecy value disappears.

i tied invalidating the window for every paint, that results to major flickering.

thank you