In my project i'm using com msword library (MSO.DLL) for do something with word documents. In next code i can't getting document pointer from open method when i start my application as Windows Service. But it's working if i start as .exe app. Maybe somebody can provide idea what's wrong and what i can extra do, for solving this? P.S. my service starting as Administator user(but it's not helping).
_DocumentPtr spDoc = NULL;
auto filename = _variant_t(sTemplate); // example: "C:\Temp\example.doc"
spDoc = spApp->Documents->Open(&filename, &vFalse, &vFalse); // RETURN NULL
auto temp = spApp->Documents->Open(&filename, &vFalse, &vFalse).GetInterfacePtr();
if(spDoc == nullptr)
{
auto error = GetLastError();
LogEvent("GET LAST ERROR (%d)", error); /// RETURN 0
LogEvent("GET temp (%s)", temp); /// RETURN null
}
i can't getting document pointer from open method when i start my application as Windows Service. But it's working if i start as .exe app.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
If you deal with open XML documents you may consider using the Open XML SDK instead, see Welcome to the Open XML SDK 2.5 for Office for more information. Otherwise, you may consider using third-party components designed for the server-side execution.