C DLL not work in Windows Service but works fine from Console app

S

Samuel R. Neff

We're using a 3rd party C DLL in a project that we don't have source
for. When we call the DLL from a console app everything works fine.
However, when we call it from a Windows Service, the DLL doesn't work
(sorry, can't be more descriptive.. no errors, but no results).

We've even taken the exact Windows Service project and put code in
main() to instantiate the service and call OnStart() instead of going
through the service base class. When we do that, it works fine (it's
essentially a console app at that point). There's something related
to the app running as a Windows Service causing problems for the 3rd
party dll.

Of course we'll try to follow up with the C authors but in the
interim... What kinds of things can cause problems in a windows
service as compared to a console app? What's different about the
environment or threading model or whatever? It's just a plain C DLL
that exports some functions and performs a bunch of complex
calculations on 40mb or so of data it stores in memory. It doesn't
interact with anything outside the DLL and doesn't use COM.

The service is run with the same user credentials as our logged in
user.

Thanks,

Sam
 
S

Samuel R. Neff

Turned out the problem was related to the current directory. The C
DLL loaded a text file from the current directory but when run as a
windows service that was always "c:\windows\system32". We set
Environment.CurrentDirectory to the directory of the exe in OnStart
and that fixed the problem.

Thanks,

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top