Я использую
[DllImport("Oleacc.dll")]
static extern int AccessibleObjectFromWindow(
int hwnd,
uint dwObjectID,
byte[] riid,
ref Excel.Window ptr);
чтобы получить экземпляр Excel, используя его дескриптор, который я получаю от идентификатора процесса экземпляра excel.
Вот как это выглядит, когда я использую эту функцию
const uint OBJID_NATIVEOM = 0xFFFFFFF0;
Guid IID_IDispatch = new Guid("{00020400-0000-0000-C000-000000000046}");
Excel.Window ptr = null;
int hr = AccessibleObjectFromWindow(hwndChild, OBJID_NATIVEOM,
IID_IDispatch.ToByteArray(), ref ptr);
Object objApp = ptr.Application;
Этот мир кода работает отлично, но единственная проблема заключается в том, что мне пришлось добавить ссылку на первичные сборники Office 2003.
Как вы можете видеть, последний параметр в функции является причиной, по которой мне нужно было добавить ссылку на Pias, поэтому мой вопрос в том, есть ли способ избежать использования Interop Assemblies, я пытался с опозданием но, возможно, я делал это неправильно, потому что я не смог заставить его работать.