Infro
2007-09-10 21:18:01 UTC
When I try to use an Image Object created in a auxilery thread, all the other
threads of the same process cannot use this object. Is there a way around
this?
This is particularly annoying because I am trying to use
CreateTimerQueueTimer for syncronizing the Image Frames.
Example:
[code]
ULONG_PTR g_GDI_Token;
HANDLE hThreadId;
UINT WINAPI CALLBACK MyThread(LPVOID lParam);
Gdiplus::Image* MyImage;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam) {
switch(message)
{
case WM_CREATE: {
SECURITY_ATTRIBUTES sa;
Gdiplus::GdiplusStartupInput l_GDI_SI;
ZeroMemory((BYTE*)&l_GDI_SI,sizeof (l_GDI_SI));
ZeroMemory((BYTE*)&sa,sizeof(sa));
sa.nLength=sizeof(sa);
sa.bInheritHandle=TRUE;
l_GDI_SI.GdiplusVersion=1;
GdiplusStartup(&g_GDI_Token,&l_GDI_SI,NULL);
CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)MyThread,NULL,NULL,(LPDWORD)&hThreadId);
WaitForSingleObject(hThreadId,INFINITE);
CloseHandle(hThreadId);
return 0;
}
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
if(!GetUpdateRect(hwnd,&rect,0)) return 0;
hdc=BeginPaint(hwnd,&ps);
Gdiplus::Graphics gr(hdc);
gr.DrawImage(MyImage,0,0,400,400);
Gdiplus::Status st=gr.GetLastStatus();
if(st) __asm int 3;
return 0;
}
case WM_DESTROY:
delete MyImage;
GdiplusShutdown(g_GDI_Token);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
UINT WINAPI CALLBACK MyThread(LPVOID lParam) {
MyImage=new Gdiplus::Image(L"Image.bmp");
ExitThread(NULL);
return NULL;
}
[/code]
This will always break at if(st), and always with InvalidParamater.
threads of the same process cannot use this object. Is there a way around
this?
This is particularly annoying because I am trying to use
CreateTimerQueueTimer for syncronizing the Image Frames.
Example:
[code]
ULONG_PTR g_GDI_Token;
HANDLE hThreadId;
UINT WINAPI CALLBACK MyThread(LPVOID lParam);
Gdiplus::Image* MyImage;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam) {
switch(message)
{
case WM_CREATE: {
SECURITY_ATTRIBUTES sa;
Gdiplus::GdiplusStartupInput l_GDI_SI;
ZeroMemory((BYTE*)&l_GDI_SI,sizeof (l_GDI_SI));
ZeroMemory((BYTE*)&sa,sizeof(sa));
sa.nLength=sizeof(sa);
sa.bInheritHandle=TRUE;
l_GDI_SI.GdiplusVersion=1;
GdiplusStartup(&g_GDI_Token,&l_GDI_SI,NULL);
CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)MyThread,NULL,NULL,(LPDWORD)&hThreadId);
WaitForSingleObject(hThreadId,INFINITE);
CloseHandle(hThreadId);
return 0;
}
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
if(!GetUpdateRect(hwnd,&rect,0)) return 0;
hdc=BeginPaint(hwnd,&ps);
Gdiplus::Graphics gr(hdc);
gr.DrawImage(MyImage,0,0,400,400);
Gdiplus::Status st=gr.GetLastStatus();
if(st) __asm int 3;
return 0;
}
case WM_DESTROY:
delete MyImage;
GdiplusShutdown(g_GDI_Token);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
UINT WINAPI CALLBACK MyThread(LPVOID lParam) {
MyImage=new Gdiplus::Image(L"Image.bmp");
ExitThread(NULL);
return NULL;
}
[/code]
This will always break at if(st), and always with InvalidParamater.