I have a 3rd party API in the form of a native dll that I call from C# using DllImport
. This native dll depends on the 3rd party application being open.
When I run the code normally the API does what is expected and drives the application. However, when I run the same code as a Windows service, even as myself, the API returns the same (undocumented) error code that I have seen when the application is closed; process explorer confirms that the native dll is correctly loaded from the application directory.
What could be causing this and how might I be able to resolve the issue?
A bit old, but it came up as one of the top results in a search. So I asume my data would still be helpfull.
The (t)rusty Office Interop DLL is the same way. You are actually starting a background instance of the Office Programm in question. The Background Instance needs an interactive Session, even if it does not show anything (design asumptions/mistakes at work). Services do not run in an interactive session since Vista. Using the override is not recommended practice. That is one of the (3?) reasons to not use Office Interop anymore.
Possible workarounds:
Based on one of the comments it appears you choose option 2, but using a Webservice instead. Unfortunately Webserices/Webapplications are usually run as Windows Service. And that is before you consider that they run under some of the most restrictive rights (since they are web reachable). So it would just get you back to square 1 or even another step backwards to square 0.
Hard to tell, but there is three possibilities I can think of: