[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Handliing c++ standard output in a Windows service

Posted on 2009-05-10
5
Medium Priority
?
402 Views
Last Modified: 2013-12-03
Hello everybody,
I'm trying to port a server of my own from Linux to Windows. After compiling the code under Cygwin, I was able to start the server in a dos console.
Then I wanted the server to run as a Windows service. Based on this tutorial, http://www.devx.com/cplus/Article/9857, I made some additional change to the code and installed the service successfully with this command:
sc create <service name> binpath= "<path with parameters>".
The service appears in the Windows service panel, but when I try to start it fails with the error 0xffffffff.
- What does this error code mean?
- Is this failure due to the use of standard ouput streams in the service?
- Under Linux the output streams were redirected in a log file within a bash script. What is the best way to achieve the same functionality under Windows?

Thanks,
Thierry Feuzeu
0
Comment
Question by:kamiche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 24354731
The error code is simply '-1' - is it possible that your code returns that somewhere?
Regarding the output streams, what are you using them for?
If it is only log output, 'freopen()' could be used to redirect them to a file from your code.
0
 

Author Comment

by:kamiche
ID: 24355129
The output streams are only used for logging purpose. I'll use freopen to redirect std output streams. With ouputs in a file I'll certainly be able to debug the program.
By now, I can't not tell where the error code -1 comes from.
0
 
LVL 86

Expert Comment

by:jkr
ID: 24355417
Can you try to add some diagnostic output, e.g. like the following to see how far your service gets in starting up? That output can be watched using 'DebugView' (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx).
oid
__cdecl
DbgReport ( char* pszFormat, ...) {
 
    static char s_acBuf [ 2048];
 
    va_list args;
 
    va_start ( args, pszFormat);
 
    vsprintf ( s_acBuf, pszFormat, args);
 
    OutputDebugStringA ( s_acBuf);
 
    va_end ( args);
}
 
// ...
 
DbgReport("In 'service_main()', command line is %s\n", GetCommandLine());

Open in new window

0
 

Author Comment

by:kamiche
ID: 24372846
I'm now able to output strings using the function above. I could'nt achieve this using standard io, even if they were redirected to a file with freopen. The output file alway remains empty. So I had to replace all calls to io functions with calls to DbgReport.
However, the service doesn't start, and it seems to me that the program halts on "select" system call.
Is there any issue or restriction to take into account when using socket in windows services? I recall that the program is being ported from Linux to Windows using Cygwin.

I'm going to do more tests and report any useful information.
0
 
LVL 86

Accepted Solution

by:
jkr earned 750 total points
ID: 24375573
>>and it seems to me that the program halts on "select" system call.
>>Is there any issue or restriction to take into account when using socket in
>>windows services?

Yup, here we are: Your problem is that services running under the 'LocalSystem' account have almost OS privileges, but are not allowed to use _any_ networking facilities. To overcome this, make sure to assign your service to run under a predefined user account (preferrably one belonging to the admin group) which does have network access (this is usually done by specifying an account name&password in the call to 'CreateService()', but you're also able to change this from the 'services' control panel applet).
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question