调用本机DLL从.NET Windows服务失败 [英] Call to native DLL fails from a .NET Windows service

查看:176
本文介绍了调用本机DLL从.NET Windows服务失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在,我从C#中使用调用的DllImport 本机DLL形式的第三方API。这个本地的dll依赖于第三方应用程序被打开。

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.

当我运行code常的API做什么预期和驱动程序。然而,当我运行相同的code作为Windows服务,甚至为自己的API返回相同的(无证)错误code,我已经看到,当应用程序被关闭;进程资源管理器确认本机的dll被正确地从应用程序目录加载。

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?

推荐答案

很难说,但有三种可能性,我能想到的:

Hard to tell, but there is three possibilities I can think of:

  • 您的服务有需要与桌面交互UI组件选项选中
  • 对窗口服务的工作目录%WINDIR%\ SYSTEM32(例如C:\ Windows \ System32下),你的DLL有使用相对路径引用其他资源无法找到code
  • 您的服务使用与在两个不同的会话中运行的应用程序netpipe通信

这篇关于调用本机DLL从.NET Windows服务失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆