I'm desperately trying to get a small GapiDraw application working in a .NET panel on the PocketPC. I'm aware that this has been discussed before on this forum. However, I'm quite new to GapiDraw (and unfortunately to C++ in general - so I hope my questions are not too stupid
) and with the information I could find so far I'm somewhat stuck right now...
In a nutshell, here's my attempt on a "Hello World" GapiDraw .NET panel: In my C++ .dll, there are two main methods I'm P/Invoking from .NET:
The first one creates a backbuffer CGapiDrawSurface (and paints some stuff on it).
The second one (PaintOntoHandle) gets an IntPtr to the control's window via P/Invoke and is supposed to draw the contents of the backbuffer onto the panel.
Here's also the C# code that I am using to get the handle of the panel's window:
The application seems to create the backbuffer without problems. However, calling the PaintOntoControl method results in an access violation.
Any ideas? Any piece of help would be greatly appreciated!
Thanks,
Ray
In a nutshell, here's my attempt on a "Hello World" GapiDraw .NET panel: In my C++ .dll, there are two main methods I'm P/Invoking from .NET:
The first one creates a backbuffer CGapiDrawSurface (and paints some stuff on it).
The second one (PaintOntoHandle) gets an IntPtr to the control's window via P/Invoke and is supposed to draw the contents of the backbuffer onto the panel.
- Code:
extern "C" __declspec(dllexport) HANDLE CreateBackBuffer(int width, int height)
{
m_width = width;
m_height = height;
CGapiDraw* g_gapidraw = new CGapiDraw();
CGapiDisplay* g_display = new CGapiDisplay(g_gapidraw);
g_display->CreateOffscreenDisplay(0, width, height);
backbuffer = g_display->GetBackBuffer();
[... draw some stuff on the backbuffer here ...]
backbuffer->GetDC(pDC);
return backbuffer;
}
extern "C" __declspec(dllexport) bool PaintOntoHandle(HWND hControl)
{
bool result = false;
if (hControl)
{
if (HDC hdc = GetDC(hControl))
{
if (*pDC)
{
BitBlt(hdc, 0, 0, m_width, m_height, *pDC, 0, 0, SRCCOPY);
result = true;
}
ReleaseDC(hControl, hdc);
}
}
return result;
}
Here's also the C# code that I am using to get the handle of the panel's window:
- Code:
private IntPtr ControlHandle
{
get
{
bool captureState = control.Capture;
control.Capture = true;
IntPtr hwnd = GetCapture();
control.Capture = captureState;
return hwnd;
}
}
The application seems to create the backbuffer without problems. However, calling the PaintOntoControl method results in an access violation.
Any ideas? Any piece of help would be greatly appreciated!
Thanks,
Ray