Managed C++ UserControl->Handle to Unmanaged HDC

G

Guest

I'm developing a .Net wrapper for an unmanaged C/C++ lib. The lib creates bitmaps and paints them in a clients window. To do its job, the lib only needs the HDC of the client/wrapper

My idea is to implement a Usercontrol in managed C++. This control forwards its handle to the lib and the lib paints to it


__gc public class MapView : public UserContro
{
public
MapView(

InitializeComponent()
int iTmp = this->Handle.ToInt32()
HWND hWnd = *(HWND*)&(iTmp)
HDC dc = ::GetDC(hWnd)

m_pIMapView = new PaintLib()
m_pIMapView->SetDrawContext(dc)
}

private
mas::_IMapView* m_pIMapView

void OnPaint(PaintEventArgs* args

m_pIMapView->Paint()
UserControl::OnPaint(args)


void Dispose(Boolean disposing

__super::Dispose(disposing)
}

---------------------------------------------------------------------------------------------------------------------------------

But this does not work. By calling SetDrawContext the lib tries to clear the content of the HDC, this is the first thing that fails. Even when I'm not calling the Lib and try to paint to the .Net DC directly by adding these lines to the constructor of MapView class

POINT pts[] = {{0,0}, {100,100}}
Polyline(dc , pts, 2)

the Polyline is painted but the disposing of the control fails. Can anybody lead me to a simple solution? Perhaps I have to allocate something or release manually or marshall...

Thanks for your help

Michael Ring
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top