NT Service in PBDLL60 
Author Message
 NT Service in PBDLL60

Anyone got any half baked ideas or samples on creating an NT service in
PBDLL60?
I do these at the moment in VB5 using a Microsoft OCX, but they are a bit
unstable.
Is PB threadsafe? - Anyone tried it ?

Regards,
Alan



Mon, 01 Apr 2002 03:00:00 GMT  
 NT Service in PBDLL60
OK, I'll bite.

What exactly is an "NT service?"

And what exactly do you mean by "threadsafe?"

This one I know:
Can PB/DLL produce multi-threaded applications? Yes.

MCM

Quote:

>Anyone got any half baked ideas or samples on creating an NT service in
>PBDLL60?
>I do these at the moment in VB5 using a Microsoft OCX, but they are a bit
>unstable.
>Is PB threadsafe? - Anyone tried it ?

>Regards,
>Alan




Tue, 02 Apr 2002 03:00:00 GMT  
 NT Service in PBDLL60

Quote:
Alan Jones wrote...
> Anyone got any half baked ideas or samples on creating
> an NT service in PBDLL60?
> I do these at the moment in VB5 using a Microsoft OCX,
> but they are a bit unstable.
> Is PB threadsafe? - Anyone tried it ?

Alan, I've written two NT Services in PB.

You'd be surprised at how straightforward it is to write them
in PB, as an NT Service is a normal program that has no GUI,
and responds to certain pre-defined calls from the NT Service
Control Manager. In fact, I wrote mine with PBCC20 so they
could also be run as console applications, and they support
command-line options. This could also be done, I suppose,
in PBDLL60, in which it could have a GUI mode when started
via a normal exec (calls PBMain() or WinMain()) versus
starting via the SCM, which calls ServiceMain()...

I highly recommend the book "Professional NT Services"
by Kevin Miller; Wrox Press 1998 ISBN: 1-861001-30-4.
This book is written for C++ programmers, but if you plan
to do many Windows apps with PB, you'll have to learn to
read C/C++ at some point (if you don't already). I'd also
written services in VB using a third party product
called "NT Service Master", and they actually worked well,
but when I "switched" to PB as my primary development too,
I tried to recreate them in PB as a learning exercise, and
succeeded. Thus, I no longer need the "NT Service Master"
ocx product, and would be willing to sell it to you for
quite a bit less than I paid for it. (Email me if you're
interested.)

The only thing you have to leave PB for when dealing with
an NT service is the event message resource dll, which isn't
necessarily related to the service itself, but is for the
Event Viewer application to look up the event ids you send
to the eventlog via ReportEventA... The message resource
file is compiled with MC.EXE and then added to a standard
resource script, which is then compiled to a resource file,
then added to a project and compiled to a DLL. For some reason,
I couldn't get it to work properly when I converted it to
a PBR (via PBRES.EXE) and put it in a PB DLL, but on a lark
I tried creating an empty DLL project in VC++ and adding
the resource file to it, and compiling the "empty" dll. Imagine
my surprise when it actually worked :) I have code for both
PB and VB that will log to the NT Event log (without the
embarrassing "VB Runtime" Event source that VB'S App.Logevent
gives you).

Anyway, I'm rambling, but to answer your question, yes,
NT Services can absolutely be written in PB. But, you have
to read a *lot* of C/C++ docs to do it :)

- Troy



Tue, 02 Apr 2002 03:00:00 GMT  
 NT Service in PBDLL60
This WHOULD be cool for the PB ftp-site!

A little to-start example (and doc)?

Quote:

>Alan Jones wrote...

>> Anyone got any half baked ideas or samples on creating
>> an NT service in PBDLL60?
>> I do these at the moment in VB5 using a Microsoft OCX,
>> but they are a bit unstable.
>> Is PB threadsafe? - Anyone tried it ?

>Alan, I've written two NT Services in PB.

>You'd be surprised at how straightforward it is to write them
>in PB, as an NT Service is a normal program that has no GUI,
>and responds to certain pre-defined calls from the NT Service
>Control Manager. In fact, I wrote mine with PBCC20 so they
>could also be run as console applications, and they support
>command-line options. This could also be done, I suppose,
>in PBDLL60, in which it could have a GUI mode when started
>via a normal exec (calls PBMain() or WinMain()) versus
>starting via the SCM, which calls ServiceMain()...

>I highly recommend the book "Professional NT Services"
>by Kevin Miller; Wrox Press 1998 ISBN: 1-861001-30-4.
>This book is written for C++ programmers, but if you plan
>to do many Windows apps with PB, you'll have to learn to
>read C/C++ at some point (if you don't already). I'd also
>written services in VB using a third party product
>called "NT Service Master", and they actually worked well,
>but when I "switched" to PB as my primary development too,
>I tried to recreate them in PB as a learning exercise, and
>succeeded. Thus, I no longer need the "NT Service Master"
>ocx product, and would be willing to sell it to you for
>quite a bit less than I paid for it. (Email me if you're
>interested.)

>The only thing you have to leave PB for when dealing with
>an NT service is the event message resource dll, which isn't
>necessarily related to the service itself, but is for the
>Event Viewer application to look up the event ids you send
>to the eventlog via ReportEventA... The message resource
>file is compiled with MC.EXE and then added to a standard
>resource script, which is then compiled to a resource file,
>then added to a project and compiled to a DLL. For some reason,
>I couldn't get it to work properly when I converted it to
>a PBR (via PBRES.EXE) and put it in a PB DLL, but on a lark
>I tried creating an empty DLL project in VC++ and adding
>the resource file to it, and compiling the "empty" dll. Imagine
>my surprise when it actually worked :) I have code for both
>PB and VB that will log to the NT Event log (without the
>embarrassing "VB Runtime" Event source that VB'S App.Logevent
>gives you).

>Anyway, I'm rambling, but to answer your question, yes,
>NT Services can absolutely be written in PB. But, you have
>to read a *lot* of C/C++ docs to do it :)

>- Troy



Tue, 02 Apr 2002 03:00:00 GMT  
 NT Service in PBDLL60

Quote:
E.B. Knoppert (NL) wrote...
> This WHOULD be cool for the PB ftp-site!

> A little to-start example (and doc)?

I feared this would happen <grin>... The code is under
contract, and "out of my hands" so to speak. However,
I am writing a generic NT Service template and I'll
gladly give it to the PB ftp site. Someone else already
wrote one, but it's a trifle incomplete, but a fantastic
starting place. Search Altavista for +PB +service +NT
and you'll find it. I know it sounds lame to cop out
and not give up the code, but I don't own the code;
the Federal Aviation Administration (we're contractors)
owns it. However, my generic event logging code, in
its original poorly-coded and sloppy version, including
the message resource dll, is available on my website
at http://submain.com/logger.zip. I'd be a bit embarrassed
for *that* to show up on the PB website, as it's not
pretty code and borrows variable names, etc from its
parent project (so some of them don't seem to make much
sense)... It does compile, but make sure you fix the
path to the dll so you don't get that
   "The description for Event ID ( 1 ) in Source ( RS )
    could not be found. It contains the following
    insertion string(s)"
error. This is what happens when you don't fix the
path to the DLL. I recommend using GetModuleFileName
and parsing the path out of it to set the DLL path
rather than hard-coding the path in like my sample code
does. I'll fix that as well, clean it up, and submit
it to the PB ftp site. I'll work on these this weekend.

- Troy

  Your mouse has moved. Windows must be restarted for
  the change to take effect. Reboot now?



Tue, 02 Apr 2002 03:00:00 GMT  
 NT Service in PBDLL60


Quote:
> And what exactly do you mean by "threadsafe?"

If you have a GLOBAL variable and two threads access it simultaneously,
it's not considered "thread-safe".

While powerbasic does not and can not prevent the programmer from writing
code that is not thread-safe, PowerBASIC itself is thread-safe.  All of
our internal RTL routines use semaphores to prevent any clashes with
internal shared buffers.

--Dave



Tue, 02 Apr 2002 03:00:00 GMT  
 NT Service in PBDLL60
Good enough for me Dave,

I'm gonna give one of these NT Service doo-hickies a go !!!

Alan


Quote:
> While PowerBASIC does not and can not prevent the programmer from writing
> code that is not thread-safe, PowerBASIC itself is thread-safe.  All of
> our internal RTL routines use semaphores to prevent any clashes with
> internal shared buffers.

> --Dave



Tue, 02 Apr 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. FTP client in PBDLL60

2. dumb terminal program needed for PBDLL60

3. Asm in PBDLL60

4. packaged app as NT service?

5. NT Service Pack 6 & TPS

6. Clarion App as an NT Service

7. Using CW for NT Services

8. Running a Clarion program as an NT service

9. Running Application as NT Service

10. Running a Program as a NT service

11. Starting VWave server (PPD Visual Wave Server 1.0) as a service under NT

12. Clarion apps as NT Services Application

 

 
Powered by phpBB® Forum Software