views:

227

answers:

2

I've perused the MSDN documentation and I couldn't find a statement one way or the other. What I'm interested in is:

  1. Can I call GdiplusStartup() on one thread and then use Gdiplus on another thread? Or do I need to call GdiplusStartup() for each thread?
  2. If I have a Bitmap object on thread 1 and different one on thread 2, can they both call Bitmap::DrawImage() at the same time, or do I need to add locking to ensure serialization?

Thanks.

+1  A: 

The MSDN documentation states 'You can call GdiplusStartup on one thread and call GdiplusShutdown on another thread', which would indicate that you only need to call GdiplusStartup() once for your process (and use it from any thread).

I'm not sure about question 2. (I think what you meant was can you call Graphics::DrawImage( bitmap ) at the same time?) You would create a different Graphics class in each thread, right? So there should be no problem.

Alex Deem
I have confirmed this is the case.
jeffamaphone
A: 

Partial answer of question 2, according to MSDN - Security Considerations: GDI+:

Thread Synchronization

It is possible for more than one thread to have access to a single GDI+ object. However, GDI+ does not provide any automatic synchronization mechanism. So if two threads in your application have a pointer to the same GDI+ object, it is your responsibility to synchronize access to that object.

Some GDI+ methods return ObjectBusy if a thread attempts to call a method while another thread is executing a method on the same object. Do not try to synchronize access to an object based on the ObjectBusy return value. Instead, each time you access a member or call a method of the object, place the call inside a critical section, or use some other standard synchronization technique.

dalle