服务中的有效HWND [英] valid HWND in a Service
问题描述
您好!
我已经专业从事java项目多年,但是
做了极少的C / C ++编码而且只是
VB.Net中的一些小东西。
现在我正在尝试用VC ++ .Net写一个Windows服务
应该使用第三方SDK接收图像数据并通过网络服务将其发送出去
。
在第三方SDK中有要求HWND传递给它的函数
。然后它使用该手柄后面的组件直接绘制
图像(实际上我认为它的作用是获得
位置和组件尺寸以及通过directX
overlay)。但是,它还支持注册自定义回调
方法,其中传递实际的原始图片数据。
通过编写自定义回调方法,我可以收到所有我需要的数据,
,但前提是我首先提供了一个有效的HWND(NULL和0两个
导致一个异常,说明Windowhandle无效)。 br />
因为我需要整个东西作为Windows服务运行我没有一个真正的窗口或窗体组件的
句柄,所以我正在寻找一种方法
创建一个虚拟窗口组件,即外观和感觉。比如第三方方法的实际组件。
希望任何人都能提供一些如何处理这个问题的信息。
亲切的问候,
Kolja
" Kolja M?rtens" < ha*@haznet.dewrote in message
news:g6 ********** @ online.de ...
您好!
我已经专业从事Java项目多年,但是
已经完成了极少的C / C ++编码和
VB.Net中的一些小东西。
现在我正在尝试用VC ++ .Net写一个Windows服务>
应该使用第三方SDK接收图像数据并通过网络服务将其发送出去
。
在第三方sdk那里是一个需要将HWND传递给它的函数
。然后它使用该手柄后面的组件直接绘制图像
(实际上我认为它的作用是获得位置和
组件的尺寸和绘图通过directX overlay)。但是,
还支持注册一个自定义回调方法,其中实际的原始
图片数据被传递给。
通过写作一个自定义回调方法我可以收到我需要的所有数据,
但是只有我首先提供有效的HWND(NULL和0两个
导致例外声明Windowhandle无效)。
因为我需要整个东西作为Windows服务运行我没有一个真正的窗口或窗体组件的
句柄,所以我寻找一种方法来创建一个虚拟窗口组件,即外观和感觉。就像第三方方法的实际组件一样。
您可以在服务中创建一个隐藏窗口没有问题(如果它不是隐藏的话,它会显示它会显示)。
RegisterClass和CreateWindow API应该可以正常工作。只需创建没有WS_VISIBLE风格的
窗口。
你可能想在带有消息循环的线程上这样做。
>
Mark
-
Mark Salsbery
Microsoft MVP - Visual C ++
>
希望任何人都可以提供一些有关如何处理此问题的信息。
亲切问候,
Kolja
Mark Salsbery [MVP]写道:
>
您可以在服务中创建一个隐藏窗口没有问题(如果它不是隐藏的话,它会显示它会显示)。
RegisterClass和CreateWindow API应该可以正常工作。只需在没有WS_VISIBLE风格的窗口中创建
。
你可能想在带有消息循环的线程上执行此操作:)
谢谢你的回复,我不确定我是否理解你的意思。
在我读完你的帖子之前我已经尝试手动打开一个窗口
调用CreateWindow(这次是形成一个.Net控制台应用程序,用于
测试)。
继承我试过的东西(经过几个小时的googeling) :
HWND hWnd = CreateWindow(" STATIC","",0,0,0,0,NULL,NULL,NULL,
NULL) ;
它编译,但是hWnd没有被正确初始化,我试着研究
RegisterClass如你所提到的那样。
" Kolja M?rtens" < ha*@haznet.dewrote in message
news:g6 ********** @ online.de ...
Mark Salsbery [MVP]写道:
>>
在服务中创建隐藏窗口应该没有问题(不是<如果它不是被隐藏的话它会显示出来。
RegisterClass和CreateWindow API应该可以正常工作。只需创建没有WS_VISIBLE风格的窗口。
你可能想在带有消息循环的线程上执行此操作:)
谢谢你的回复,我不确定我是否理解你的意思。
在我看到你的帖子之前我已经尝试手动打开一个窗口
调用CreateWindow(这次形成一个.Net控制台应用程序,用于
测试)。
继承我尝试的东西(经过几个小时的googeling):
HWND hWnd = CreateWindow(" STATIC",",0,0,0,0,NULL,NULL,NULL,
NULL);
>
它编译,但是hWnd没有正确初始化,我试着研究
RegisterClass如你所提到的那样。
请参阅
使用窗口类
http://msdn.microsoft.com/en-us/libr...75(VS.85).aspx
Mark
-
Mark Salsbery
Microsoft MVP - Visual C ++
Hello!
I''ve been professionally working on java projects for several years, but
have done extremely little C/C++ coding and just a few little things in
VB.Net.
Right now I''m trying to write a Windows Service in VC++ .Net thats
supposed to use a 3rd party SDK do receive Image data and send it out
through a webservice.
In the 3rd party sdk there is a function that requires a HWND to be
passed to it. It then uses the component behind that handle to paint the
images straight to it (Actually what i think it does is getting the
position and dimension of the component and drawing via directX
overlay). However, it also supports registering a custom callback
methode where the actual raw picture data is passed to.
By writing a custom callback methode i can receive all the data I need,
but only if i provide a valid HWND in the first place (NULL and 0 both
result in an exception stating the Windowhandle was invalid).
Since I need the whole thing to run as a windows service I dont have a
handle to a real Window or Form component, so Im looking for a way to
create a dummy window component, that is going to "look and feel" like a
real component to the 3rd party method.
Hope anyone can provide some information on how to deal with this problem.
Kind regards,
Kolja
"Kolja M?rtens" <ha*@haznet.dewrote in message
news:g6**********@online.de...Hello!
I''ve been professionally working on java projects for several years, but
have done extremely little C/C++ coding and just a few little things in
VB.Net.
Right now I''m trying to write a Windows Service in VC++ .Net thats
supposed to use a 3rd party SDK do receive Image data and send it out
through a webservice.
In the 3rd party sdk there is a function that requires a HWND to be passed
to it. It then uses the component behind that handle to paint the images
straight to it (Actually what i think it does is getting the position and
dimension of the component and drawing via directX overlay). However, it
also supports registering a custom callback methode where the actual raw
picture data is passed to.
By writing a custom callback methode i can receive all the data I need,
but only if i provide a valid HWND in the first place (NULL and 0 both
result in an exception stating the Windowhandle was invalid).
Since I need the whole thing to run as a windows service I dont have a
handle to a real Window or Form component, so Im looking for a way to
create a dummy window component, that is going to "look and feel" like a
real component to the 3rd party method.
You should have no problem creating a hidden window in your service (not
that it would show if it wasn''t hidden anyway).
The RegisterClass and CreateWindow APIs should work fine. Just create the
window without the WS_VISIBLE style.
You''ll maybe want to do this on a thread with a message loop :)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
>
Hope anyone can provide some information on how to deal with this problem.
Kind regards,
Kolja
Mark Salsbery [MVP] wrote:>
You should have no problem creating a hidden window in your service (not
that it would show if it wasn''t hidden anyway).
The RegisterClass and CreateWindow APIs should work fine. Just create
the window without the WS_VISIBLE style.
You''ll maybe want to do this on a thread with a message loop :)Thanx for your reply, Im not sure if I understand exactly what you mean.
Allready before I read your post I tried to open a window by manually
calling CreateWindow (this time form a .Net console application for
testing).
Heres what I tried (after googeling for hours):
HWND hWnd = CreateWindow("STATIC", "", 0, 0, 0, 0, 0, NULL, NULL, NULL,
NULL);
It compiles, but hWnd is not propperly initialized, Ill try research on
RegisterClass as you mentioned.
"Kolja M?rtens" <ha*@haznet.dewrote in message
news:g6**********@online.de...Mark Salsbery [MVP] wrote:>>
You should have no problem creating a hidden window in your service (not
that it would show if it wasn''t hidden anyway).
The RegisterClass and CreateWindow APIs should work fine. Just create
the window without the WS_VISIBLE style.
You''ll maybe want to do this on a thread with a message loop :)
Thanx for your reply, Im not sure if I understand exactly what you mean.
Allready before I read your post I tried to open a window by manually
calling CreateWindow (this time form a .Net console application for
testing).
Heres what I tried (after googeling for hours):
HWND hWnd = CreateWindow("STATIC", "", 0, 0, 0, 0, 0, NULL, NULL, NULL,
NULL);
It compiles, but hWnd is not propperly initialized, Ill try research on
RegisterClass as you mentioned.
See
Using Window Classes
http://msdn.microsoft.com/en-us/libr...75(VS.85).aspx
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
这篇关于服务中的有效HWND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!