PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GapiDraw in .NET panel (yet another attempt)

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 :oops:) 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.

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
Ok, I have come somewhat further. However I still have a problem: I can only call the PaintOntoHandle method once. The full code of the method is shown below:

Code:

extern "C" __declspec(dllexport) bool PaintOntoHandle(HWND hControl)
{
bool result = false;
HDC pDC = NULL;

if (hControl)
{
if (HDC hdc = GetDC(hControl))
{
backbuffer->GetDC(&pDC;);
if (pDC)
{
BitBlt(hdc, 0, 0, m_width, m_height, pDC, 0, 0, SRCCOPY);
result = true;
}
ReleaseDC(hControl, hdc);
}
}

return result;
}


After calling the method once, the innermost if-clause is no longer entered:

Code:

if (pDC)
{
BitBlt(hdc, 0, 0, m_width, m_height, pDC, 0, 0, SRCCOPY);
result = true;
}


Do I have to specially release the pDC variable? Just deleting it results in an access violation. As I said, I'm new to GapiDraw and also mostly C++, so I hope my questions aren't to newbie-ish.

Thanks,
ray