Create a Service with .NET

  • Thread starter Thread starter Andrea
  • Start date Start date
A

Andrea

In a Windows CE .NET 4.2 device can i write a service with the .NET CF ?
If not how can i call a .net assembly from a ec++ program ?

Thanks in advance

Andrea Adami
 
A 'service' is a DLL with a certain set of exported functions whose names
follow a convention. I think that you cannot write a service in .NET CF.
Further, I don't believe that you can really call a .NET assembly from an
eVC++ program, either.

Maybe, if you told us what you wanted to do, rather than how you want to do
it, we might be able to offer a suggestion.

Paul T.
 
As Paul stated, a service must export a certain set of functions, so you
cannot do it with the CF. There is also no hosting support, so you cannot
call .NET assemblies from unmanaged code.
 
I have like an industrial controller for home automation, the hardware is
x86 based.
I want use Windows CE .NET 4.2 as O.S.
I have to write a program that start when the device start
the program job is a loop to read data either from serial port or http,
manage it, and write it back to either serial port or http.
I think the best way is write a service so i can start and stop it from the
telnet
I would like to write it in .net cf because:
1) debug at source level
2) best integration with visual studio
3) more easier than ec++ 4.0
4) i think that the .net cf is the future

What do you think ?

Andrea Adami
 
I've done all of those things in an industrial controller based on x86 and
there's no reason at all to do them in a service. You can easily create a
scheme to start and stop your 'service', whether it's based on C/C++ or .NET
CF (a named event which you can set to stop things is quite easy, and anyone
can call CreateProcess() to start a program). I have some more specific
responses, also:

1) You can do this in eVC or in .NET CF. This is a wash; no advantage to
..NET CF or to eVC.

2) Certainly that's true. You might count eVC as the winner here, though,
given that it's free. What's your reason for wishing for VS integration?
Maybe I'm missing something.

3) I would not say that this is true, for your application. Direct access
to hardware is far easier from C/C++ than it is from managed code.

For your application, I'd use eVC. You can do everything that you've
mentioned and it's relatively easy to do. Don't forget that, unless the
controller already has Windows CE.NET 4.2 in it, you'll need to purchase
Platform Builder in order to generate an OS for the controller and that
makes this a *much* bigger project.

Paul T.
 
Thanks to Paul and Chris: your comments are very important for me.
I'm new to WindwsCe system.
I have the platform builder for WindowsCE .NET 4.2 so itsn't a problem
create a new os image.
I have some points to discuss with you:
1) When you think i have to use a service instead a normal program ?
2) I would like to use .NET CF for my coding because i used the Visual
Studio .NET and the .NET Framework but i'm new to evc++ and the winapi
programming and i think that for the future the way will be on the .NET CF.
So i try to use .NET CF but, of course, if it's not possible i will start
learning c++ and win api programming, in that case have you some suggestion
? Articles, links, ecc... ? SAMPLES ?
3) Probably i have to comunicate only either via serial port or network so
the direct access to hardware is not a must for me and, and if i need it i
can wirte a small dll to access the hardware and call it from .net code.
4) a good advantage of .NET code is the portability accross platform.
5) i have to create something like an industrial controller, the productoin
envionment will have more than one of this devices, these devices have to
comunicate each others trough the ethernet network so i think to create on
it a program that manage the logic of the controller and can comunicate with
the others controller trough the netwotk via something like web service. (i
hope that my description is clear enough)

Thanks again

Andrea Adami

Paul G. Tobey said:
I've done all of those things in an industrial controller based on x86 and
there's no reason at all to do them in a service. You can easily create a
scheme to start and stop your 'service', whether it's based on C/C++ or ..NET
CF (a named event which you can set to stop things is quite easy, and anyone
can call CreateProcess() to start a program). I have some more specific
responses, also:

1) You can do this in eVC or in .NET CF. This is a wash; no advantage to
.NET CF or to eVC.

2) Certainly that's true. You might count eVC as the winner here, though,
given that it's free. What's your reason for wishing for VS integration?
Maybe I'm missing something.

3) I would not say that this is true, for your application. Direct access
to hardware is far easier from C/C++ than it is from managed code.

For your application, I'd use eVC. You can do everything that you've
mentioned and it's relatively easy to do. Don't forget that, unless the
controller already has Windows CE.NET 4.2 in it, you'll need to purchase
Platform Builder in order to generate an OS for the controller and that
makes this a *much* bigger project.

Paul T.

Andrea said:
I have like an industrial controller for home automation, the hardware is
x86 based.
I want use Windows CE .NET 4.2 as O.S.
I have to write a program that start when the device start
the program job is a loop to read data either from serial port or http,
manage it, and write it back to either serial port or http.
I think the best way is write a service so i can start and stop it from the
telnet
I would like to write it in .net cf because:
1) debug at source level
2) best integration with visual studio
3) more easier than ec++ 4.0
4) i think that the .net cf is the future

What do you think ?

Andrea Adami

"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> ha scritto
nel messaggio news:%[email protected]...
A 'service' is a DLL with a certain set of exported functions whose names
follow a convention. I think that you cannot write a service in .NET CF.
Further, I don't believe that you can really call a .NET assembly from an
eVC++ program, either.

Maybe, if you told us what you wanted to do, rather than how you want
to
do
it, we might be able to offer a suggestion.

Paul T.

In a Windows CE .NET 4.2 device can i write a service with the .NET
CF
 
Note: *Having* PB in your possession is *not* the same as saying that
building an OS for a new device is going to be easy. If you haven't done
this before, count on it taking 4-6 weeks to get it working correctly and
getting drivers for the various components you have. If you have a Board
Support Package for the device you are building for, that may shorten things
to a week or two.

1) You never *have* to make something a service. There's always another
alternative.

2) You've never done Windows API programming? "Programming Windows" by
Petzold is the standard reference on that. If you are going to be writing
code to drive hardware, don't use managed code. Maybe someday that will be
the way it is done, but you'll be trying to type with oven mitts on right
now. If all you're doing is sending some messages, that's not much of an
'industrial controller'...

Everything else you've mentioned is fine, but doesn't change my opinion.

Paul T.


Andrea said:
Thanks to Paul and Chris: your comments are very important for me.
I'm new to WindwsCe system.
I have the platform builder for WindowsCE .NET 4.2 so itsn't a problem
create a new os image.
I have some points to discuss with you:
1) When you think i have to use a service instead a normal program ?
2) I would like to use .NET CF for my coding because i used the Visual
Studio .NET and the .NET Framework but i'm new to evc++ and the winapi
programming and i think that for the future the way will be on the .NET CF.
So i try to use .NET CF but, of course, if it's not possible i will start
learning c++ and win api programming, in that case have you some suggestion
? Articles, links, ecc... ? SAMPLES ?
3) Probably i have to comunicate only either via serial port or network so
the direct access to hardware is not a must for me and, and if i need it i
can wirte a small dll to access the hardware and call it from .net code.
4) a good advantage of .NET code is the portability accross platform.
5) i have to create something like an industrial controller, the productoin
envionment will have more than one of this devices, these devices have to
comunicate each others trough the ethernet network so i think to create on
it a program that manage the logic of the controller and can comunicate with
the others controller trough the netwotk via something like web service. (i
hope that my description is clear enough)

Thanks again

Andrea Adami

Paul G. Tobey said:
I've done all of those things in an industrial controller based on x86 and
there's no reason at all to do them in a service. You can easily create a
scheme to start and stop your 'service', whether it's based on C/C++ or .NET
CF (a named event which you can set to stop things is quite easy, and anyone
can call CreateProcess() to start a program). I have some more specific
responses, also:

1) You can do this in eVC or in .NET CF. This is a wash; no advantage to
.NET CF or to eVC.

2) Certainly that's true. You might count eVC as the winner here, though,
given that it's free. What's your reason for wishing for VS integration?
Maybe I'm missing something.

3) I would not say that this is true, for your application. Direct access
to hardware is far easier from C/C++ than it is from managed code.

For your application, I'd use eVC. You can do everything that you've
mentioned and it's relatively easy to do. Don't forget that, unless the
controller already has Windows CE.NET 4.2 in it, you'll need to purchase
Platform Builder in order to generate an OS for the controller and that
makes this a *much* bigger project.

Paul T.

Andrea said:
I have like an industrial controller for home automation, the hardware is
x86 based.
I want use Windows CE .NET 4.2 as O.S.
I have to write a program that start when the device start
the program job is a loop to read data either from serial port or http,
manage it, and write it back to either serial port or http.
I think the best way is write a service so i can start and stop it
from
the
telnet
I would like to write it in .net cf because:
1) debug at source level
2) best integration with visual studio
3) more easier than ec++ 4.0
4) i think that the .net cf is the future

What do you think ?

Andrea Adami

"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> ha scritto
nel messaggio A 'service' is a DLL with a certain set of exported functions whose names
follow a convention. I think that you cannot write a service in
..NET
CF.
Further, I don't believe that you can really call a .NET assembly
from
an
eVC++ program, either.

Maybe, if you told us what you wanted to do, rather than how you
want
..NET
 
1) You never *have* to make something a service. There's always another
alternative.

What are the advantage to write a service ? Why the webserver is implemented
as service instead as normal program ?
now. If all you're doing is sending some messages, that's not much of an
'industrial controller'...

i said:
"5) i have to create something like an industrial controller the ..."
^^^

Thank you again

Andrea Adami
 
1) Well, the only advantage that I can think of is that the service manager
provides the structure for starting and stopping the service. As I said,
this is no big deal, especially in C/C++, but you don't have to do anything
but respond appropriately to the service manager if you are a service.
There are no privilege advantages, no performance advantages, no hardware
access advantages.

5) Ah.

Paul T.
 
Do you have some suggestions to provide such structure (fot starting and
stopping) in a .nt cf program ?

Andrea Adami


Paul G. Tobey said:
1) Well, the only advantage that I can think of is that the service manager
provides the structure for starting and stopping the service. As I said,
this is no big deal, especially in C/C++, but you don't have to do anything
but respond appropriately to the service manager if you are a service.
There are no privilege advantages, no performance advantages, no hardware
access advantages.

5) Ah.

Paul T.

Andrea said:
1) You never *have* to make something a service. There's always another
alternative.

What are the advantage to write a service ? Why the webserver is implemented
as service instead as normal program ?
now. If all you're doing is sending some messages, that's not much of an
'industrial controller'...

i said:
"5) i have to create something like an industrial controller the ..."
^^^

Thank you again

Andrea Adami


"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> ha scritto
nel messaggio news:[email protected]...
Note: *Having* PB in your possession is *not* the same as saying that
building an OS for a new device is going to be easy. If you haven't done
this before, count on it taking 4-6 weeks to get it working correctly and
getting drivers for the various components you have. If you have a Board
Support Package for the device you are building for, that may shorten things
to a week or two.

1) You never *have* to make something a service. There's always another
alternative.

2) You've never done Windows API programming? "Programming Windows" by
Petzold is the standard reference on that. If you are going to be writing
code to drive hardware, don't use managed code. Maybe someday that
will
be
the way it is done, but you'll be trying to type with oven mitts on right
now. If all you're doing is sending some messages, that's not much of an
'industrial controller'...

Everything else you've mentioned is fine, but doesn't change my opinion.

Paul T.
 
I'd create a thread to handle someone notifying me that it's time to stop
(starting I'd just handle by having the other program call CreateProcess()
to start me). That thread would call CreateEvent() to make (or access an
already-existing), named event. There's probably a place in OpenNetCF where
it's already declared for you, or maybe a post that you can find in the
archives via Google. In the thread, while normal processing occurs in the
main thread, a call to WaitForSingleObject() would be made. I'd probably
arrange things so that this call waited forever (pass INFINITE in the last
parameter). If the call ever returns, do whatever you need to do to cause
the program to exit (you might close the main form, call Application.Exit or
whatever).

If, in the main thread you want to exit the program, it would then be
necessary to call SetEvent() on the event, causing the exit thread to return
from WaitForSingleObject() and exit the event (rather than closing the main
form or whatever directly). You need to do this so that both threads are
sure to be exited.

Paul T.

Andrea Adami said:
Do you have some suggestions to provide such structure (fot starting and
stopping) in a .nt cf program ?

Andrea Adami


Paul G. Tobey said:
1) Well, the only advantage that I can think of is that the service manager
provides the structure for starting and stopping the service. As I said,
this is no big deal, especially in C/C++, but you don't have to do anything
but respond appropriately to the service manager if you are a service.
There are no privilege advantages, no performance advantages, no hardware
access advantages.

5) Ah.

Paul T.

Andrea said:
1) You never *have* to make something a service. There's always another
alternative.

What are the advantage to write a service ? Why the webserver is implemented
as service instead as normal program ?

now. If all you're doing is sending some messages, that's not much
of
an
'industrial controller'...

i said:
"5) i have to create something like an industrial controller the ..."
^^^

Thank you again

Andrea Adami


"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> ha scritto
nel messaggio Note: *Having* PB in your possession is *not* the same as saying that
building an OS for a new device is going to be easy. If you haven't done
this before, count on it taking 4-6 weeks to get it working
correctly
and
getting drivers for the various components you have. If you have a Board
Support Package for the device you are building for, that may shorten
things
to a week or two.

1) You never *have* to make something a service. There's always another
alternative.

2) You've never done Windows API programming? "Programming Windows" by
Petzold is the standard reference on that. If you are going to be writing
code to drive hardware, don't use managed code. Maybe someday that will
be
the way it is done, but you'll be trying to type with oven mitts on right
now. If all you're doing is sending some messages, that's not much
of
an
'industrial controller'...

Everything else you've mentioned is fine, but doesn't change my opinion.

Paul T.
 
Hi Paul,
I found out an advantage to use service: in Windows CE .NET you have only 32
task.
So to create a program instead to create a service consume one task.

Andrea

Paul G. Tobey said:
1) Well, the only advantage that I can think of is that the service manager
provides the structure for starting and stopping the service. As I said,
this is no big deal, especially in C/C++, but you don't have to do anything
but respond appropriately to the service manager if you are a service.
There are no privilege advantages, no performance advantages, no hardware
access advantages.

5) Ah.

Paul T.

Andrea said:
1) You never *have* to make something a service. There's always another
alternative.

What are the advantage to write a service ? Why the webserver is implemented
as service instead as normal program ?
now. If all you're doing is sending some messages, that's not much of an
'industrial controller'...

i said:
"5) i have to create something like an industrial controller the ..."
^^^

Thank you again

Andrea Adami


"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> ha scritto
nel messaggio news:[email protected]...
Note: *Having* PB in your possession is *not* the same as saying that
building an OS for a new device is going to be easy. If you haven't done
this before, count on it taking 4-6 weeks to get it working correctly and
getting drivers for the various components you have. If you have a Board
Support Package for the device you are building for, that may shorten things
to a week or two.

1) You never *have* to make something a service. There's always another
alternative.

2) You've never done Windows API programming? "Programming Windows" by
Petzold is the standard reference on that. If you are going to be writing
code to drive hardware, don't use managed code. Maybe someday that
will
be
the way it is done, but you'll be trying to type with oven mitts on right
now. If all you're doing is sending some messages, that's not much of an
'industrial controller'...

Everything else you've mentioned is fine, but doesn't change my opinion.

Paul T.
 
Yes, that's a good point. On Pocket PC devices, sometimes you have a lot of
useless programs running. I have less than half that number running on any
device that I support, even with a Telnet server, Web server, wireless
status program, programmable function key program, program to allow remote
access to serial ports, etc., etc. It just depends on your target system
(and your programming capabilities; if you can use C, then go at it with
services).

Paul T.

Andrea said:
Hi Paul,
I found out an advantage to use service: in Windows CE .NET you have only 32
task.
So to create a program instead to create a service consume one task.

Andrea

Paul G. Tobey said:
1) Well, the only advantage that I can think of is that the service manager
provides the structure for starting and stopping the service. As I said,
this is no big deal, especially in C/C++, but you don't have to do anything
but respond appropriately to the service manager if you are a service.
There are no privilege advantages, no performance advantages, no hardware
access advantages.

5) Ah.

Paul T.

Andrea said:
1) You never *have* to make something a service. There's always another
alternative.

What are the advantage to write a service ? Why the webserver is implemented
as service instead as normal program ?

now. If all you're doing is sending some messages, that's not much
of
an
'industrial controller'...

i said:
"5) i have to create something like an industrial controller the ..."
^^^

Thank you again

Andrea Adami


"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> ha scritto
nel messaggio Note: *Having* PB in your possession is *not* the same as saying that
building an OS for a new device is going to be easy. If you haven't done
this before, count on it taking 4-6 weeks to get it working
correctly
and
getting drivers for the various components you have. If you have a Board
Support Package for the device you are building for, that may shorten
things
to a week or two.

1) You never *have* to make something a service. There's always another
alternative.

2) You've never done Windows API programming? "Programming Windows" by
Petzold is the standard reference on that. If you are going to be writing
code to drive hardware, don't use managed code. Maybe someday that will
be
the way it is done, but you'll be trying to type with oven mitts on right
now. If all you're doing is sending some messages, that's not much
of
an
'industrial controller'...

Everything else you've mentioned is fine, but doesn't change my opinion.

Paul T.
 
Back
Top