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,
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.