如何在.NET中获得主要的forM句柄 [英] How to get the main forM handle in .NET
问题描述
我正在尝试使用需要主窗口句柄的第三方DLL作为
参数。
例如MyFunc(WHND MyHandle);
示例如下所示:
结果= MyFunc(句柄);
其中处理是Win32句柄。
尝试使用编写的示例导致编译器错误:
无法将参数5从''int''转换为' 'HWND''
首先,HWND基本上不是无符号整数吗?我尝试过类型
施放和其他一些东西,但编译器没什么好看的。
有谁知道如何使这个工作?
I am trying to use a 3rd party DLL that requires the main window handle as
a parameter.
e.g. MyFunc(WHND MyHandle);
The example looks something like this:
Result = MyFunc(Handle);
Where "Handle" is the Win32 handle.
Trying to use the example as written results in a compiler error:
cannot convert parameter 5 from ''int'' to ''HWND''
First isn''t the HWND basically an unsigned integer? I have tried type
casting and several other things, but nothing the compiler likes.
Does anyone know how to make this work?
推荐答案
" Fred Hebert" < FH ***** @ hotmail.com>在消息中写道
news:Xn ******************************* @ 207.46.248。 16 ...
"Fred Hebert" <fh*****@hotmail.com> wrote in message
news:Xn*******************************@207.46.248. 16...
我正在尝试使用需要主窗口句柄的第三方DLL作为参数。
MyFunc(WHND MyHandle);
错字?你的意思是这个?
MyFunc(HWND MyHandle);
这个例子看起来像这样:
结果= MyFunc(Handle);
其中Handle是Win32句柄。
尝试使用编写的示例导致编译器错误:
无法将参数5从''int''转换为''HWND''
首先,完全按照书面形式发布代码总是一个好主意;魔鬼
在细节中。
这是一个猜测:如果你必须,施放第五个参数:
更改...(... x,...);
到
...(... (HWND)x,...);
首先,HWND基本上不是无符号整数吗?
使用Von Neumann机器,一切基本上都是整数。那么,什么?
:-)
我尝试过类型转换和其他一些事情,
但编译器不喜欢。
I am trying to use a 3rd party DLL that requires the main window handle as
a parameter.
e.g. MyFunc(WHND MyHandle);
Typo? You mean this?
MyFunc(HWND MyHandle);
The example looks something like this:
Result = MyFunc(Handle);
Where "Handle" is the Win32 handle.
Trying to use the example as written results in a compiler error:
cannot convert parameter 5 from ''int'' to ''HWND''
First, it is always a good idea to post code exactly as written; the devil
is in the details.
This is a guess: If you must, cast the 5th parameter:
change ...(... x, ...);
to
...(... (HWND) x, ...);
First isn''t the HWND basically an unsigned integer?
Using Von Neumann machines, everything is basically an integer. So, what?
:-)
I have tried type casting and several other things,
but nothing the compiler likes.
>
正如我所说,显示错误的代码,错误消息的确切文本以及您尝试过的
。
问候,
将
As I said, show the bad code, the exact text of the error message and what
you have tried.
Regards,
Will
对于错字感到抱歉,只是想简化。
它来自不同的地方,但这里是实际的代码:
typedef int(_stdcall * pOmniConnect)(char * IpAddress,
unsigned int端口,
unsigned int超时,
unsigned char EncryptionKey [16],
HWND NotifyWindow);
。 ...
pOmniConnect OmniConnect;
....
加载dll并解决地址(与问题无关)
....
OmniConnect(IpEdit->文字,
PortEdit->文字 - > ToInt32,
TimeoutEdit-> Text-> ToInt32,
BinKey,
句柄); //这行是问题
如写:
错误C2664:''int(... func template ...)'':无法转换参数5
从''int''到''HWND''
尝试类型转换例如(HWND)句柄);
错误C2440" ''type cast'':无法从''System :: IntPtr''转换为''HWND''
尝试了各种各样的 - > Handle和Handle-> xxx转换但类似的问题
问题。
Sorry about the typo, was just trying to simplify.
It''s pulled from various places, but here is the actual code:
typedef int (_stdcall *pOmniConnect) (char * IpAddress,
unsigned int Port,
unsigned int Timeout,
unsigned char EncryptionKey[16],
HWND NotifyWindow);
....
pOmniConnect OmniConnect;
....
The dll is loaded and addresses resolved (not relevant to problem)
....
OmniConnect(IpEdit->Text,
PortEdit->Text->ToInt32,
TimeoutEdit->Text->ToInt32,
BinKey,
Handle); // this line is the problem
As Written:
error C2664: ''int(... the func template ...)'': cannot convert parameter 5
from ''int'' to ''HWND''
Tried type casting e.g. (HWND)Handle);
error C2440" ''type cast'' : cannot convert from ''System::IntPtr'' to ''HWND''
Tried various this->Handle, and Handle->xxx conversions but similar
problems.
" Fred Hebert" < FH ***** @ hotmail.com>在消息中写道
news:Xn ******************************* @ 207.46.248。 16 ...
"Fred Hebert" <fh*****@hotmail.com> wrote in message
news:Xn*******************************@207.46.248. 16...
对于拼写错误感到抱歉,只是想简化。
它来自不同的地方,但这里是实际代码:
typedef int(_stdcall * pOmniConnect)(char * IpAddress,
unsigned int Port,
unsigned int Timeout,
unsigned char EncryptionKey [16],
HWND NotifyWindow );
...
pOmniConnect OmniConnect;
...
dll已加载并解决了地址(与问题无关)
... OmniConnect(IpEdit-> Text,
PortEdit-> Text-> ToInt32,
TimeoutEdit-> Text-> ToInt32,
BinKey,
句柄); //这一行是问题
如编写:
错误C2664:''int(... func模板......)'':无法转换参数5
来自''int ''到''HWND''
尝试类型转换例如(HWND)句柄);
错误C2440 ''type cast'':无法从''System :: IntPtr''转换为''HWND''
试过各种各样的 - > Handle,和Handle-> xxx转换但类似
问题。
Sorry about the typo, was just trying to simplify.
It''s pulled from various places, but here is the actual code:
typedef int (_stdcall *pOmniConnect) (char * IpAddress,
unsigned int Port,
unsigned int Timeout,
unsigned char EncryptionKey[16],
HWND NotifyWindow);
...
pOmniConnect OmniConnect;
...
The dll is loaded and addresses resolved (not relevant to problem)
...
OmniConnect(IpEdit->Text,
PortEdit->Text->ToInt32,
TimeoutEdit->Text->ToInt32,
BinKey,
Handle); // this line is the problem
As Written:
error C2664: ''int(... the func template ...)'': cannot convert parameter 5
from ''int'' to ''HWND''
Tried type casting e.g. (HWND)Handle);
error C2440" ''type cast'' : cannot convert from ''System::IntPtr'' to ''HWND''
Tried various this->Handle, and Handle->xxx conversions but similar
problems.
如何宣布Handle?
问候,
将
How is Handle declared?
Regards,
Will
这篇关于如何在.NET中获得主要的forM句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!