views:

160

answers:

2

in a function named buildtexture, it loaded the image and build texture for OpenGL, when i called CreateDIBSection, it will creat a bitmap. If the function buildtexture was called as a normal member function, there will be nothing wrong. But if i called this member function in a thread, the CreateDIBSection will return 0 that means it failed. And even the GetLastError alse returned 0 after the calling of CreateDIBSection. I guess the thread has no enough spaces to create the bitmap. And i don't know how to solve this problem. Any one can help me? Thank you very much!

A: 

Not likely to be an out of memory error.

CreateDibSection needs a HDC, where did you get it? Did another thread get it and then hand it to you?

It is legal to use a DC in a thread other than the one that got it. but you need to insure that use of the DC is serialized when you use it in more than one thread.

Make sure that the DC is still valid when you try and use it, and that only one thread at a time is trying to use it.

John Knoeller
i get the hdc with hdcTemp = CreateCompatibleDC(GetDC(0)), and then the CreateDibSection will be called as hbmpTemp = CreateDIBSection(hdcTemp, as your saied, mycolleague also found that the use of the HDC is wrong without any synchronized. He thought that i should use memory dc in the thread. Now i'm a little understand this problem, thank you for your help John Knoeller.
snail
A: 

That fault you have is mean you not delete Hdc Before CreateDIBSection must be delete new Hdc. But how! what is new HDC come Just get the old Hdc first befor change.

After CreateDIBSection at first Hdc will change when very time Resize form , Close form and Minimize form

If that CreateDIBSectio return 0 You much be delete Hdc

hDib = CreateDIBSection(hDCRef, bi, DIB_RGB_COLORS, lPtr, 0, 0) if (hDib = 0) then DeleteObject hdc if (hDib <> 0) then hBmpOld = SelectObject(hdc, hDib) 'already create not need to delete

Dav