I'm using the following way to get the running instance of MSWord.
MSWord.Window wordWin = null;
uint OBJID_NATIVEOM = 0xFFFFFFF0;
Guid IID_IDispatch = new Guid("{00020400-0000-0000-C000-000000000046}");
Guid iid = IID_IDispatch;
Object accObject = null;
int hr = OleAcc.AccessibleObjectFromWindow(msWordHndl, OBJID_NATIVEOM, ref iid, ref accObject);
wordWin = accObject as MSWord.Window
if(wordWin != null) // <----(1)
{
// do something.
}
Here msWordHndl is a valid running instance of MS Word handle.
The above code (1) works fine every where except on some of our customers machines.
What are the things that we need to make sure why the msWordHndl is not being recognized as MSWord COM object? i.e. (1) fails always. The same doesnt happen on our machines/environment.
The following have been verified on the customers machine.
- Office 2010 plus is installed
- Primary Interop Assemblies(PIA) has been installed.
- Verified that .NET programmability support is included while installing MS Office.
Update: Running into the same problems as mentioned in Can Microsoft.office.interop.word.dll work without installing office?
But in my case, Office is INSTALLED on the customer computer.
I did verify that the Microsoft.Office.Interop.Word.dll is located in c:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\14.0.0...\ One small difference I see is the DLL name is prefixed with "Policy.12.0". To make sure this is causing any issues, I checked in another customer computer where the MSWord access works fine but that computer also has the same prefix to the DLL.