互操作问题 [英] Interop question

查看:74
本文介绍了互操作问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c#中执行某些win32消息时,我得到了意想不到的结果。

以下示例假设在另一个应用程序的

按钮控件中返回图像的句柄但它返回一个负面的

句柄...是否有人知道它为什么会返回一个无效的句柄,如

" -989523277" ??


IntPtr ImageHandle =

Win32.SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero,I ntPtr.Zero);

MessageBox.Show(ImageHandle.ToString());


注意:第三个参数设置为IMAGE_BITMAP(0);如果

按钮不包含图像,则返回0.


谢谢...

When executing some win32 messages in c# I get unexpected results.
The following example is suppose to return the handle of an image in a
button control of another application but it return a negative
handle...is anybody know why it return an invalid handle like
"-989523277" ??

IntPtr ImageHandle =
Win32.SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero,I ntPtr.Zero);
MessageBox.Show(ImageHandle.ToString());

Note : the third param is set to IMAGE_BITMAP (0); it return 0 if
the button contain no image.

Thanks...

推荐答案

2008年8月21日星期四20:35:26 -0700,michelqa< mi ****** @ yahoo.cawrote:
On Thu, 21 Aug 2008 20:35:26 -0700, michelqa <mi******@yahoo.cawrote:

在c#中执行一些win32消息时,我得到了意想不到的结果。

以下示例假设在另一个应用程序的

按钮控件中返回图像的句柄,但它返回否定

句柄...有人知道为什么它会返回一个无效的句柄,例如

" -989523277" ??
When executing some win32 messages in c# I get unexpected results.
The following example is suppose to return the handle of an image in a
button control of another application but it return a negative
handle...is anybody know why it return an invalid handle like
"-989523277" ??



你能更具体一点吗?为什么你认为价值-989523277

无效的句柄值?你真的试过把它用作HBITMAP

并且失败了吗?你能否展示一个简洁但完整的代码示例,

可靠地展示你实际遇到的任何问题?


Pete

Can you be more specific? Why do you believe the value "-989523277" to be
an invalid handle value? Have you actually tried to use it as an HBITMAP
and had that fail? Can you show a concise-but-complete code sample that
reliably demonstrates whatever problem you''re actually having?

Pete


8月21日,11:44 * pm,Peter Duniho < NpOeStPe ... @nnowslpianmk.com>

写道:
On Aug 21, 11:44*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:

2008年8月21日星期四20:35:26 -0700 ,michelqa< miche ... @ yahoo.cawrote:
On Thu, 21 Aug 2008 20:35:26 -0700, michelqa <miche...@yahoo.cawrote:

在c#*中执行某些win32消息时,我得到了意想不到的结果。

以下示例假设在另一个应用程序的

按钮控件中返回图像的句柄,但它返回一个否定的

句柄...是否有人知道它返回的原因一个无效的句柄,如

" -989523277" ??
When executing some win32 messages in c# *I get unexpected results.
The following example is suppose to return the handle of an image in a
button control of another application but it return a negative
handle...is anybody know why it return an invalid handle like
"-989523277" ??



你能更具体一点吗? *为什么你认为价值-989523277 tobe *

无效的句柄值? *您是否真的尝试将其用作HBITMAP *

并且失败了? *你能否展示一个简洁但完整的代码样本*

可靠地展示你实际遇到的任何问题?


Pete


Can you be more specific? *Why do you believe the value "-989523277" tobe *
an invalid handle value? *Have you actually tried to use it as an HBITMAP *
and had that fail? *Can you show a concise-but-complete code sample that *
reliably demonstrates whatever problem you''re actually having?

Pete



我认为它是无效的,因为它是否定的,因为我无法使用
在我的应用程序中重新创建位图。 .it返回一个Generic

例外


//句柄=另一个应用程序的按钮句柄

IntPtr ImageHandle =

Win32.SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero,I ntPtr.Zero);

MessageBox.Show(ImageHandle.ToString());

System.Drawing.Bitmap Bitmap =

System.Drawing.Bitmap.FromHbitmap(ImageHandle); //通用异常

来自gdi..invalid句柄?

//只想在这里获得一个可用的位图

I suppose it''s invalid since it''s negative and since i''m not able to
recreate the bitmap in my application...it return a "Generic
exception"

//Handle = button handle of another application
IntPtr ImageHandle =
Win32.SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero,I ntPtr.Zero);
MessageBox.Show(ImageHandle.ToString());
System.Drawing.Bitmap Bitmap =
System.Drawing.Bitmap.FromHbitmap(ImageHandle); //generic exception
from gdi..invalid handle?
// Just want to get a usable bitmap here


好的,我会尝试解释这个问题:

1-我知道WM_GETIMAGE假设返回一个hImage hex

c50512b3(3305444019 )...我知道因为我正在记录消息

在SPY ++中

2-我的c#app中的sendMessage返回-989523277(或

8975925797277995699修改sendmessage定义时返回

长而不是IntPtr)***为什么会出现这种差异???? ****

3-即使正确的图像处理硬编码如下:

System.Drawing.Image MyImg =

System.Drawing .Image.FromHbitmap((IntPtr)330544401 9);

我收到错误:算术运算导致溢出。


据我所知,FromHbitmap想要一个IntPtr和3305444019是一个整数

一个整数


不要认为一个更完整的例子将有助于理解这个问题

但这是我的例子......我有一个Win32应用程序,我想要复制

按钮图像并将图像放在按钮或图片框中

my c#


[DllImport(" user32.dll")]

public static extern IntPtr SendMessage(IntPtr hwnd,int msg,IntPtr

wparam,IntPtr lparam);

int BM_GETIMAGE = 0x00F6;

IntPtr ImageHandle =

SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero ,IntPtr.Zero);

MessageBox.Show(ImageHandle.ToString());

System.Drawing.Image MyImg =

System.Drawing.Image.FromHbitmap((IntPtr)330544401 9); //算术

操作导致溢出。

//System.Drawing.Image MyImg =

System.Drawing.Image.FromHbitmap( ImageHandle); //例外

按钮Button1 =新按钮();

Button1.Image = MyImg;
Ok , I''ll try to explain the problem :
1- I know that WM_GETIMAGE is suppose to return an hImage hex
c50512b3 (3305444019) ... I know that because I''m logging the message
in SPY++
2- My sendMessage in my c# app return -989523277 (or
8975925797277995699 when modifying sendmessage definition to return a
long instead of a IntPtr) *** Why this difference???? ****
3- Even with the correct image handle hardcoded like this :
System.Drawing.Image MyImg=
System.Drawing.Image.FromHbitmap((IntPtr)330544401 9);
I get the error : Arithmetic operation resulted in an overflow.

As I understand it FromHbitmap want an IntPtr and 3305444019 is to big
for a Integer

Dont think a more complete example will help to understand the problem
but here is my example...I have a Win32 application and I want to copy
Button image from it and put the image in a button or a picturebox in
my c#

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hwnd, int msg, IntPtr
wparam, IntPtr lparam);
int BM_GETIMAGE = 0x00F6;
IntPtr ImageHandle =
SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero,IntPtr. Zero);
MessageBox.Show(ImageHandle.ToString());
System.Drawing.Image MyImg=
System.Drawing.Image.FromHbitmap((IntPtr)330544401 9); //Arithmetic
operation resulted in an overflow.
//System.Drawing.Image MyImg=
System.Drawing.Image.FromHbitmap(ImageHandle); //Exception
Button Button1 = new Button();
Button1.Image=MyImg;


这篇关于互操作问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆