473,780 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

valid HWND in a Service

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
Jul 23 '08
11 4639
Kolja Märtens wrote:
Ben Voigt [C++ MVP] schrieb:
>>
ShowWindow should have worked fine and set the WS_VISIBLE flag even
when the application runs on a service desktop.

What do you mean by "service desktop"?
The Callback is indeed invoked even when the user is logged of as long
as the Service has the right to interact with the desktop.

Big drawback is, once a user logs in, the Window is displayed and
thats something I definetly dont want.
If you don't check that "Interact with user's desktop" permission (which is
not even available in newer versions of Windows), your service runs in a
separate desktop just for services. This way it can create windows, pass
messages to other services' windows, etc, but there's a security barrier
between windows of trusted services and windows in the user's logon session.
This prevents the "shatter attack".
>
>However, if the callback is triggered by WM_PAINT it will only
happen when the window really is on the screen. However, you can
InvalidateWind ow and SendMessage WM_PAINT to the window yourself.

I tracked all window messages in my dummy window class and passed them
on to the NativeWindow WndProc. Seems like the window was only used
during initialization because when the process starts drawing the
Pictures (in an overlay i suppose) there are no more window messages
coming in.

Heres what WndProc is getting:
36 WM_GETMINMAXINF O
129 WM_NCCREATE
131 WM_NCCALCSIZE
1 WM_CREATE
24 WM_SHOWWINDOW
70 WM_WINDOWPOSCHA NGING
70 WM_WINDOWPOSCHA NGING
28 WM_ACTIVATEAPP
13 WM_GETTEXT
134 WM_NCACTIVATE
642 WM_IME_NOTIFY
641 WM_IME_SETCONTE XT
7 WM_SETFOCUS
6 WM_ACTIVATE
13 WM_GETTEXT
133 WM_NCPAINT
20 WM_ERASEBKGND
71 WM_WINDOWPOSCHA NGED
5 WM_SIZE
3 WM_MOVE

I just realized that there is indeed one WM_PAINT.
From what I know about video overlay I think the Background of the
Window is changed to magenta to mark the aerea to overlay.

Ill have to read about what InvalidateWindo w does...
>>>I suppose I should overwrite the function that is used for
detecting if the window is visible and sinply return true, but i
have no clue what funtion that is.
still looking for that.

Bad idea. The function is provided by Microsoft inside USER32.dll.

I was hoping for something like "bool isVisible()" in the
Windowclass... I know by now this is not the way things work around
here :)
You mean like http://msdn.microsoft.com/en-us/libr...30(VS.85).aspx ?

Though if you were hoping for "virtual bool isVisible()" that you could
override, you're out of luck. There's one implementation inside USER32.DLL
which is used for all windows, and there's nothing like a v-table that would
allow you to change it. Only the window procedure can be replaced on a
per-window basis (this is called subclassing).
Jul 28 '08 #11
Just wanted to take a chance and say thank you to everyone who supported
me on this.
I talked to the company that developed the SDK and they told me that the
next SDK version is going to support a way to have the callback invoked
without the need of a HWND in the first place.

Seems I had luck this time since now I have the pre release version and
things should be a lot easier.
Jul 29 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11046
by: Andrew Moore | last post by:
Hi All, I have a managed C++ class that makes calls into the Win32 API. I specifically am trying to take a Handle from a .NET form and convert it to a HWND to pass to a Win32 functions. The code works properly but I get the following compiler warning: warning C4312: 'reinterpret_cast' : conversion from 'int' to 'HWND' of greater size.
1
6977
by: Zeya | last post by:
I have this code, which uses WMI to operate on Windows service from C# code. When Service.InvokeMethod is called, the method throws an exception: System.Management Operation is not valid due to the current state of the object. at System.Management.ManagementObject.InvokeMethod(String methodName, Object args)
17
7110
by: Bonj | last post by:
Is PostQuitMessage(?) different to PostMessage(hWnd, WM_QUIT, ... ) ? I've got a window in a DLL (the same one experiencing the issue below, "return value of WM_QUIT") in which PostMessage(hWnd, WM_QUIT, ... ) works, but PostQuitMessage doesn't. I would assume this to be the case as PostQuitMessage can't possibly know the hWnd I'm wanting it to operate on. So why does the docs advise you to use that?
5
4114
by: MrBewsher | last post by:
Hi, I'm using VB.Net and writing an NT service that runs in the system account in the background with no interaction with the desktop. I'm running it on XP Pro. I'd like to get the URL of any Internet Explorer process a logged in user is running. I can get a list of process IDs and from that use
4
1613
by: --== Alain ==-- | last post by:
Hi, When i debugged my code (see below) from my overrider WndProc method, i discovered that update has alway left, right, botton and top set to 0. therefore i wonder if my hwnd point to the right value. how can i know that ? thx.
15
30113
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
How can I pass a C++ HWND to and from C# and Managed C++?
3
3962
by: c2 | last post by:
hi, i face a problem when click the icon , my login will prompt this message String was not recognized as a valid Boolean See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.FormatException: String was not recognized as a valid Boolean.
0
1315
by: BarryM | last post by:
I was told that this piece coding to find the es_password state in c# would work but an error message saying hWnd does not exist in the current context internal static class UnsafeNativeMethods { public const int GWL_STYLE = -16; public const int ES_PASSWORD = 0x20; public static extern int GetClassName(HandleRef hWnd, System.Text.StringBuilder lpClassName, int nMaxCount); ...
3
4721
by: =?Utf-8?B?YW5kcmV3?= | last post by:
I have a web application demo page and a web service. On my machine everything works great. In our test environment the web service is working fine... when I point the demo page on my machine to the test environment web service I get results as expected. The demo page in the test environment which is pointed at the web service in the test environment doesn't work at all... instead I end up with this
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.