Handles and Memory Management

  • Thread starter Thread starter Gary Nastrasio
  • Start date Start date
G

Gary Nastrasio

I have a Windows Form in .NET 2.0 who's handle (HWND) I need for use in
native C++ code. As I understand it, the handle from my windows form
control may change managed memory locations arbitarily, which in that
case will cause problems with my native code. Is there a way to tell
..NET to never change the memory location of my window handle?

I create my form like so:
MyForm^ foo = gcnew MyForm();

Thanks,

Gary
 
Gary Nastrasio said:
I have a Windows Form in .NET 2.0 who's handle (HWND) I need for use in
native C++ code. As I understand it, the handle from my windows form
control may change managed memory locations arbitarily, which in that case
will cause problems with my native code. Is there a way to tell .NET to
never change the memory location of my window handle?

Not exactly. Your form may change locations in memory, but the HWND is an
opaque value that won't ever change during the lifetime of the form (or
anything derived from System.Windows.Forms.Control).

-cd
 
Hi Gary!
I have a Windows Form in .NET 2.0 who's handle (HWND) I need for use in
native C++ code. As I understand it, the handle from my windows form
control may change managed memory locations arbitarily, which in that
case will cause problems with my native code. Is there a way to tell
..NET to never change the memory location of my window handle?

A handle is just a value, and it is not bound to any memory location...
I create my form like so:
MyForm^ foo = gcnew MyForm();

You will get the hWnd with

foo->Handle
http://msdn2.microsoft.com/system.windows.forms.control.handle.aspx


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top