C++非托管 DLL 无法在 IIS 7.5 上启动 Excel
我们有一个 C++ Win32 DLL,可以从 Excel 读取数据。
该应用程序使用以下行创建应用程序:
xl.CreateInstance(L"Excel.Application");
我想在 .NET 项目上使用此 DLL,因此我构建了一个 C++/CLI 包装器,并在 C# Web 应用程序上引用该包装器 DLL。
Win32(非托管)-> C++/CLI(托管)-> C#
Web 应用程序在 Visual Studio 集成 Web 服务器上工作正常,但是当我部署到 IIS 时,它在上面的行上失败并返回错误“无效指针”。
我认为这可能是权限问题,所以我模拟了 Web 应用程序,但它不起作用。看起来 IIS 不允许从非托管 C++ DLL 打开 Excel。我可以从 C# 打开,但有很多 C++ 代码来读取电子表格,我不想再次编写它。
我正在运行 IIS 7.5,并且应用程序池允许 Win32 应用程序。
你能帮我吗?
此致,
we have a C++ Win32 DLL that reads data from Excel.
The application uses the following line to create an application:
xl.CreateInstance(L"Excel.Application");
I want to use this DLL on a .NET Project, so I've built a C++/CLI Wrapper, and reference the wrapper DLL on a C# Web Application.
Win32 (unmanaged) -> C++/CLI (managed) -> C#
The Web Application works fine on the Visual Studio integrated Web Server, however when I deploy to IIS it fails on the above line and returns the error "Invalid pointer".
I thought it could be a permissions problem so I impersonated the Web App but it didn't work. Looks like IIS does not allow open Excel from an unmanaged C++ DLL. I could open from C# but there is a lot of C++ code to read the spreadsheets and I don't want to write it again.
I am running IIS 7.5 and the applicaiton pool allow Win32 Applications.
Could you help me?
Best regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MS 不支持在服务器上使用 Office Interop - 请参阅 http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
自从 Windows Vista MS 引入了一些与安全相关的措施来阻止 Windows 服务(IIS 只是一个特殊情况)从做“类似桌面”的事情......这意味着你必须规避一些安全措施(仅靠模拟是不够的!)才能让它工作(不推荐!)。
集成 VS Web 服务器不会模拟 IIS 在权限等方面的行为。
要在服务器场景中处理 Excel,有多种选择(免费和商业):
我可以推荐 Aspose.Cells 和 Flexcel...没有尝试SpreadsheetGear 但听到+读到了很多关于它的好东西...
免费选项(尽管仅适用于较新的 xlsx 格式!)例如 来自 MS 的 OpenXML 2 和 EPPlus。
Using Office Interop on the server is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Since Windows Vista MS introduced several security-related measures which prevent a Windows Service (IIS is just a special case of that) from doing "desktop-like" things... which means you would have to circumvent several security measures (impersonation alone won't cut it!) to get it to work (NOT recommended!).
The Integrated VS web server does NOT simulate the behaviour of IIS regarding permissions etc.
To deal with Excel in a server-scenario there are several options (free and commercial) out there:
I can recommend Aspose.Cells and Flexcel... didn't try SpreadsheetGear but hear+read lots of good things about it...
Free options (though for the newer xlsx format only!) are for example OpenXML 2 from MS and EPPlus.