使用SendMessage将字符串传递给其他应用程序,... [英] Passing String to other Applications with SendMessage,...

查看:355
本文介绍了使用SendMessage将字符串传递给其他应用程序,...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想用EnumWindows和SendMessage模拟(同步)BroadCastSystemMessage

。我不想使用

的BroadcastSystemMessage因为它需要SE_TCB_NAME

特权(你没有正常情况)。所以我决定使用带有SendMessage的

EnumWindows。我在这里尝试的是传递一个

WM_USER + 1111与LParam和WParam,指向字符串。

但是当我尝试用另一端的字符串获取

Marshal.PtrToStringAnsi,

String本身为空。我不知道这里的错误是什么,所以

a小代码:


IntPtr ptrIPAddress = IntPtr.Zero;

IntPtr ptrGUID = IntPtr.Zero;


ptrIPAddress =

Marshal.AllocHGlobal(Encoding.ASCII.GetByteCount(t his.textBoxGGIPAIPAddress.Text));

ptrGUID =

Marshal.AllocHGlobal(Encoding.ASCII.GetByteCount(t his.guidApplicationGUID.ToString()));


ptrIPAddress = Marshal .StringToHGlobalAnsi(this.textBoxGGIPAIPAdd ress.Text);

ptrGUID = Marshal.StringToHGlobalAnsi(this.guidApplicationGU ID.ToString());


//( IntPtr,uint,IntPtr,IntPtr)

SendMessage(hWnd,(uint)WindowsMessages.WM_USER + 1111,ptrGUID,

ptrIPAddress);


Marshal.FreeHGlobal(ptrIPAddress);

Marshal.FreeHGlobal(ptrGUID);


在另一端我尝试这个,但没有任何东西在那里:


protected override void WndProc(ref message m)

{

if(m.Msg ==(uint)WindowsAPIClass.WindowsMessages.WM_USER + 1111)

{

String s = Marshal.PtrToStringAnsi(m.LParam );

MessageBox.Show(s);

}

base.WndProc(ref m);

}

如何做到这一点?我不能使用远程处理或类似的东西,因为

消息应该可用于运行在系统上的任何应用程序,......似乎全局内存不是真的全球,...


问候


Kerem


-

-----------------------

BesteGrüsse/致敬/ Votre bien devoue

KeremGümrükcü

Microsoft Live Space: http:// kerem-g.spaces.live.com/

最新的开源项目: http://entwicklung.junetz.de

-----------------------

此回复按原样提供,不附带任何明示或暗示的保证。

Hi,

i want to emulate a (synchronous) BroadCastSystemMessage
with EnumWindows and SendMessage. I dont want to use
the BroadcastSystemMessage because it needs the SE_TCB_NAME
Privilege (you dont have this in normal). So i decided to use the
EnumWindows with SendMessage. What i try here is to pass a
WM_USER+1111 with LParam and WParam, pointing to strings.
But when i try to get the strings at the other end with
Marshal.PtrToStringAnsi,
the String itself is empty. I dont know what the mistake here is, so
a little code:

IntPtr ptrIPAddress = IntPtr.Zero;
IntPtr ptrGUID = IntPtr.Zero;

ptrIPAddress =
Marshal.AllocHGlobal(Encoding.ASCII.GetByteCount(t his.textBoxGGIPAIPAddress.Text));
ptrGUID =
Marshal.AllocHGlobal(Encoding.ASCII.GetByteCount(t his.guidApplicationGUID.ToString()));

ptrIPAddress = Marshal.StringToHGlobalAnsi(this.textBoxGGIPAIPAdd ress.Text);
ptrGUID = Marshal.StringToHGlobalAnsi(this.guidApplicationGU ID.ToString());

//(IntPtr,uint, IntPtr,IntPtr)
SendMessage(hWnd, (uint)WindowsMessages.WM_USER + 1111, ptrGUID ,
ptrIPAddress );

Marshal.FreeHGlobal(ptrIPAddress);
Marshal.FreeHGlobal(ptrGUID);

At the other end i try this, but nothing is in there:

protected override void WndProc(ref Message m)
{
if (m.Msg == (uint) WindowsAPIClass.WindowsMessages.WM_USER + 1111)
{
String s = Marshal.PtrToStringAnsi(m.LParam);
MessageBox.Show(s);
}
base.WndProc(ref m);
}
How to do this? I cant use remoting or stuff like that, because
the message should be available for any application running on
the System,...it seems that the global memory isnt really global,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

推荐答案

"KeremGümrükcü" < ka ******* @ hotmail.comwrote in message

news:uA ************** @ TK2MSFTNGP06.phx.gbl ...
"Kerem Gümrükcü" <ka*******@hotmail.comwrote in message
news:uA**************@TK2MSFTNGP06.phx.gbl...




i希望使用EnumWindows和SendMessage模拟(同步)BroadCastSystemMessage

。我不想使用

的BroadcastSystemMessage因为它需要SE_TCB_NAME

特权(你没有正常情况)。所以我决定使用带有SendMessage的

EnumWindows。我在这里尝试的是传递一个

WM_USER + 1111与LParam和WParam,指向字符串。

但是当我尝试用另一端的字符串获取

Marshal.PtrToStringAnsi,

String本身为空。我不知道这里的错误是什么,所以

一个小代码:
Hi,

i want to emulate a (synchronous) BroadCastSystemMessage
with EnumWindows and SendMessage. I dont want to use
the BroadcastSystemMessage because it needs the SE_TCB_NAME
Privilege (you dont have this in normal). So i decided to use the
EnumWindows with SendMessage. What i try here is to pass a
WM_USER+1111 with LParam and WParam, pointing to strings.
But when i try to get the strings at the other end with
Marshal.PtrToStringAnsi,
the String itself is empty. I dont know what the mistake here is, so
a little code:



你不能通过指针交叉过程。每个应用程序都拥有它自己的完全独立的内存空间。什么是您的应用程序的有效指针是

不是另一个的有效指针。您应该查看WM_COPY_DATA消息

,因为它将复制您的字符串数据跨进程并且非常易于使用。


Michael

You can''t pass a pointer cross process. Each application has it own
completely seperate memory space. What is a valid pointer for your app is
not a valid pointer for another. You should look at the WM_COPY_DATA message
as it will copy your string data cross-process and is quite easy to use.

Michael


嗨迈克尔,


是的我知道这一点,但我仍然试图找到一种方法。我知道

WM_COPYDATA但是如果使用某种WM_USER这可能会很好。

但是因为进程是独占的我我想我必须以
的方式去WM_COPYDATA,...


问候


Kerem

-

-----------------------

BesteGrüsse/祝你好运/ Votre bien devoue

KeremGümrükcü

Microsoft Live Space: http://kerem-g.spaces.live.com/

最新的开源项目: http://entwicklung.junetz.de

-------------- ---------

此回复按原样提供,不附带任何明示或暗示的保证。
Hi Michael,

yes i know this but I still tried to find a way. I know
the WM_COPYDATA but it would be great if
this would be possible with some sort of WM_USER.
But since processes are exclusive i think i have to
go the WM_COPYDATA way,...

Regards

Kerem
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."


您好,

i想要使用EnumWindows模拟(同步)BroadCastSystemMessage

发信息。
i want to emulate a (synchronous) BroadCastSystemMessage
with EnumWindows and SendMessage.



看起来你想尝试使用SendMessage(HWND_BROADCAST,a?|)。

为什么不使用它?


(H)Serge

Seems like you''re trying to enumate SendMessage(HWND_BROADCAST, a?|) instead.
Why not use it?

(H) Serge


这篇关于使用SendMessage将字符串传递给其他应用程序,...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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