Accessing the COM interface of an application using C ++ or C

In response to the question, how can I (or find more information) automate certain functionality without user intervention from C ++ (or C) using:

  • ATL
  • Or automation code directly in C / C ++

Hello

+1


source to share


2 answers


If your application provides a type library (and Microsoft Office applications), you can navigate to it from Microsoft C ++ using the #import keyword. This will create C ++ wrappers for the COM interfaces exposed by the application.

Type libraries are often .TLB files, but they are regularly embedded as Win32 resources in executables.

To find out if an application exposes its functionality in this way, you may have to consult the application-specific documentation, since the detection (and understanding) type libraries are quite complex.



The Windows SDK includes an "OLE / COM Viewer" tool that can display Typelibrary information for a COM object in the registry or from a .TLB file or resource.

If you want to play with an application, VBScript (or JScript) gives you a quick way to experiment. They are both capable of using the OLE Automation interfaces.

+3


source


In automatic mode, you mean to have a script that launches the application, communicates with it, and performs some functions. Something like an automated test script of sorts or something.

To do this, the easiest way (if the application already exists, such as Word, Excel, Visual Studio, etc.) is to write a script in a language that supports DCOM (such as Ruby with its WIN32OLE library) and use that to call into the application.



If you are developing an application then it gets more complex, perhaps you can embed an existing scripting language in your executable and provide a way to interact with it. Perhaps there is a command line option to automatically run the script in the context of your application. Or if you want to do some serious development work you can try adding to DCOM (I haven't tried this so I don't know how much work is involved).

0


source







All Articles