com-interop

Get Currently Opened Word Document from Process

限于喜欢 提交于 2021-02-10 18:22:58
问题 The goal is to get the full path to the document opened in an instance of Microsoft Word that I have a process reference for. Pseudocode Example: Process myWordProcess = something; // This is my process reference DocumentInformation docInfo = SomeNamespace.GetDocumentInformation(myWordProcess); string documentPath = docInfo.FullName; // "C:\User\Foo\Documents\Test.docx" The starting point is a Process object which is executed by WINWORD.exe . I am not looking for a way that includes parsing

Get Currently Opened Word Document from Process

喜夏-厌秋 提交于 2021-02-10 18:21:52
问题 The goal is to get the full path to the document opened in an instance of Microsoft Word that I have a process reference for. Pseudocode Example: Process myWordProcess = something; // This is my process reference DocumentInformation docInfo = SomeNamespace.GetDocumentInformation(myWordProcess); string documentPath = docInfo.FullName; // "C:\User\Foo\Documents\Test.docx" The starting point is a Process object which is executed by WINWORD.exe . I am not looking for a way that includes parsing

Error notification from COM event handler, using interop

帅比萌擦擦* 提交于 2021-02-10 06:09:50
问题 I'm consuming a com object in c#, using com-interop. I provide an event handler to the object, which it calls after doing its thing. Here's the problem. I have some sanity-check code in the handler that throws an exception if all is not well with the world: _comObj.OnRequestCompleted += (int requestID, RequestStatus status) => { if (<sanity check fails>) throw new Exception("This is insane!!!"); ... } The com object is apparently swallowing those exceptions, because I never see them in my app

Create VB6 application using a class in a DLL, then swap out that DLL after build?

非 Y 不嫁゛ 提交于 2021-02-08 13:36:01
问题 so my question is relatively simple, can I create VB6 application that references a class in a dll, and then substitute that dll for another at runtime? Now my intial guess is... no chance in VB6. So my thoughts turned to a VB.net interop dll. Could I do it in here, and then call the interop dll from the VB? Again, my guess would be no.... but I'd be happy if someone knew differently. The only thing that I think would actually work would be DI in .Net, but I'm limited to .net 2, or 3.5 at a

Can I marshal a C-struct with a 2d array without using “unsafe”?

给你一囗甜甜゛ 提交于 2021-02-07 21:10:09
问题 I have a C DLL that I'm writing a C# interop class for. In the C DLL, one of the key methods fills a 2d structure; the structure is allocated and freed by helper methods, like so: // Simple Struct Definition -- Plain Old Data typedef struct MyPodStruct_s { double a; double b; } MyPodStruct; typedef struct My2dArray_s { MyPodStruct** arr; // allocated by Init2d; // array of arrays. // usage: arr[i][j] for i<n,j<m int n; int m; } My2dArray; void Init2d(My2dArray* s, int n, int m); void Free2d

Error Handling in C# / VBA COM Interop

六眼飞鱼酱① 提交于 2021-02-07 09:34:48
问题 I have a C# DLL being called from Excel VBA which I have exposed via a COM Callable Wrapper / COM Interop. I want to be able to pass any exceptions which occur in the C# code up onto the VBA client. Are there any recommended approaches to doing this ? Thanks. 回答1: It is possible to create your own exceptions that communicate HRESULT error codes back to VBA or other COM based callers. Here's an example that uses E_FAIL: public class ComMessageException : Exception { public ComMessageException

Register for COM Interop

假如想象 提交于 2021-02-07 03:13:05
问题 When the Register for COM Interop option in the build properties is checked, I get an error: Cannot register assembly -access denied When the option is unchecked, the project builds without any error. But my requirement is to register the COM objects as I need to use the same in VB. Can anyone help me out in this? 回答1: An extension to Frédéric Hamidi's answer (upvote for your sir), you could either run Visual Studio as administrator, or turn off the 'register for COM interop', and open up a

Register for COM Interop

荒凉一梦 提交于 2021-02-07 03:06:26
问题 When the Register for COM Interop option in the build properties is checked, I get an error: Cannot register assembly -access denied When the option is unchecked, the project builds without any error. But my requirement is to register the COM objects as I need to use the same in VB. Can anyone help me out in this? 回答1: An extension to Frédéric Hamidi's answer (upvote for your sir), you could either run Visual Studio as administrator, or turn off the 'register for COM interop', and open up a

Force .NET interop to use local COM DLL

岁酱吖の 提交于 2021-02-05 20:35:36
问题 Is it possible to force an interop assembly to reference a local copy of its associated COM DLL? Here's the scenario: I have a .NET app that references an interop assembly (Interop.OTAClient.dll), which is the interop for a COM DLL (OTAClient.dll, which is the automation API for HP Quality Center). I'm not very knowledgable on COM, but as I understand it the interop assembly looks up the COM classes via GUID references in the registry, rather than pointing to a specific file. The issue I have

Force .NET interop to use local COM DLL

£可爱£侵袭症+ 提交于 2021-02-05 20:35:21
问题 Is it possible to force an interop assembly to reference a local copy of its associated COM DLL? Here's the scenario: I have a .NET app that references an interop assembly (Interop.OTAClient.dll), which is the interop for a COM DLL (OTAClient.dll, which is the automation API for HP Quality Center). I'm not very knowledgable on COM, but as I understand it the interop assembly looks up the COM classes via GUID references in the registry, rather than pointing to a specific file. The issue I have