Handles and Memory Management

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
 
C

Carl Daniel [VC++ MVP]

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
 
J

Jochen Kalmbach [MVP]

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/
 

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