Hi,
generally speaking I'd say that, depending on how often you will use your
C++ code, it's a good idea to rewrite the C++ code to managed C++.
Unfortunately I can't tell you how big the effort is.
Points 2 and 4 ("Pass the HWND of a C# form to the C++ code, and attach it
to a C++ Window
and draw on it", "Pass the HDC of the C# form to the C++ code, and draw on
that DC") sound reasonable, too, and would be my favorite if you need a
quick and dirty solution. Note that you don't have to attach anything to the
HWND because you can get it's DC (how can you attach a window to an existing
HWND, anyway?). I'm not sure if there's a security or authentication issue
there becuase you'll have to use the InteropServices namespace though.
To point 3 ("Pass the HWND of a C++ window to C# code, and attach it to a C#
form and draw on it."): Again, how can you attach an exsiting HWND to a
window?
Hope this helps. Good luck.
Munir Husseini
"Lei Jiang" <code@263.net> schrieb im Newsbeitrag
news:OQy$pW6eEHA.372@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view] > I have a drawing application written in C++, and want to use it in a
> framework written in C#. Since the amount of C++ code is very large, it's
> unpractical to translate them to C#. So I want to use the window in C++ as
a
> control in C#. It seems there are a lot of method to do this :
>
> 1. Rebuild the C++ code in C++/CLI, and try to call it in managed world.
> 2. Pass the HWND of a C# form to the C++ code, and attach it to a C++
Window
> and draw on it.
> 3. Pass the HWND of a C++ window to C# code, and attach it to a C# form
and
> draw on it.
> 4. Pass the HDC of the C# form to the C++ code, and draw on that DC.
> 5. ...
>
> I think this is a common problem in porting old C++ code to C#, so there
> must be someone has already solved this problem. Could anyone give me some
> advice?
>
> Thanks!
>
>