what is HWND in vc++

2020-07-26 15:37发布

hai....what is the equivalent of HWND(vc++) in c#,because i want to send HWND from my c# program to the VC++ dll

5条回答
萌系小妹纸
2楼-- · 2020-07-26 16:10

That would be IntPtr, which is meant to contain unmanaged handles and pointers.

http://msdn.microsoft.com/en-us/library/system.intptr.aspx

查看更多
甜甜的少女心
3楼-- · 2020-07-26 16:10

IntPtr. Also you might read about P/Invoke calls.

查看更多
▲ chillily
4楼-- · 2020-07-26 16:15

HWND as was stated is an abbreviation for Window Handle. real type behind HWND is just a structure with an integer field. So it's analog in .Net is IntPtr

However here a quite interesting question - What the size of HWND in x64 Windows. Because IntPtr from .net then have 64 bit long. But if HWND remain 32 bit long there maybe problems

查看更多
三岁会撩人
5楼-- · 2020-07-26 16:17

HWND is similar to IntPtr.

use the following syntax

    [DllImport("ImortingDllName.dll")]
    public static extern void ExposedFunction(IntPtr hwndmsg, int all);
查看更多
做个烂人
6楼-- · 2020-07-26 16:19

HWND is a "handle to a window" and is part of the Win32 API . HWNDs are essentially pointers (IntPtr) with values that make them (sort of) point to a window-structure data. In general HWNDs are part an example for applying the ADT model.

If you want a Control's HWND see Control.Handle property. It is an IntPtr which value is an HWND.

Since HWND are not a .Net entity, they need to be released manually. This is done with Control.DestroyHandle().

Pay close attention to creation and destruction of HWND. Responsibility for object destruction is unusual in .Net and is in general a source for bugs and memory leaks.

查看更多
登录 后发表回答