A dll method does not function when called from windows service. Works in VS debug mode.


S

Shahzad Atta

Hi All,

I had a Win32 executable that does some media encoding stuff. As I need to
encode more media I decided to make it a windows service. To use it easily
in windows service I decided to wrap that exe in a Win32 dll. After
compiling the dll in STA mode I added the import directive in my c# windows
service. In the service constructor I spawn a new thread and call a method
of that dll.

Now if I run this exe as stand alone it works fine. If I run the service as
a program (doing F5 in VS 2008) it works fine. As soon as I install/register
it as a service and run it via SCM the method does get called but no
processing occur and it immediately returns from the dll call (I debuged
that service by attaching to process). I am not sure if the call ever get to
the method as on the very start of method we have added some logging to
trace the error but no log file gets generated.

Any ideas or pointers? On another note, I am executing this service under
administrator account as the dll needs to read and write files from the file
system.

Regards,
Shahzad Atta.
 
Ad

Advertisements

A

andy.johnstone

[...]
Any ideas or pointers? On another note, I am executing this service  
under administrator account as the dll needs to read and write files  
from the file system.

Impossible to know without a concise-but-complete code example that  
demonstrates the problem.

However, one thing I note in your post is that you say "after compiling  
the DLL in STA mode", which doesn't make any sense.  Single-apartment mode  
isn't something you compile code with.  It's something that is explicitly  
set on a per-thread basis during execution.  For applications, you can use  
the STAThreadAttribute attribute to have the run-time automatically  
initialize your entry-point thread, but a DLL doesn't get to control that..

So, one thing that could be an issue (_could_ be...I have no idea if this 
is actually your problem) is if you are calling code that will work only  
in STA mode, but have failed to call Thread.SetApartmentState() to  
initialize the apartment mode correctly.

Also, once installed as a service, its probably running under the
Local System account, which has different privileges than his normal
logon account.
 

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