Painting in a DLL

  • Thread starter Thread starter Hilton
  • Start date Start date
H

Hilton

Hi,

Using CF 1.0:

I writing a test for a larger project. The test is to have my C# code call
a C DLL and have the C DLL do a FillRect on my control. Are there any
examples of how to do this on the web? The C# code is:

void Fill ()
{
IntPtr hWnd = GetHWnd (this.button1);

GraphicsEx gex = GraphicsEx.FromHwnd (hWnd);

Rectangle r = this.button1.ClientRectangle;;

IntPtr hdc = gex.GetHdc ();

Function2 (hdc, ref r);
gex.Dispose ();
}

The C code is:
extern "C" __declspec(dllexport) int __cdecl Function1(int a, int b)
{
return a+b*b;
}

// Do I need to use CDC or can I use some non-MFC stuff?
extern "C" __declspec(dllexport) void __cdecl Function2(CDC *pCDC, RECT
*pRect)
{
CBrush brush;
brush.CreateSolidBrush (RGB(255,255,0));
pCDC->FillRect (pRect, &brush);
}

Function1 works correctly (FYI), Function2 crashes.

Thanks,

Hilton
 
Hi,

OK, so I have managed to do a new Control() and have my DLL written in C
paint it yellow. Woohoo. OK, now any ideas how I can do a "new Bitmap()"
and get my DLL to paint it yellow?

This is CF 1.0 so things are very limited. I'm trying CreateCompatibleDC
and Select Object etc, but not making too much progress. OpenNETCF's
GraphicsEx and BitmapEx have kinda helped, but not entirely.

Help!

Hilton
 
Back
Top