简体   繁体   中英

Accessing an application's COM interface using C++ or C

In response to question, how can I (or find more information to) certain without user intervention, from a C++ (or C) using: 某些

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

Regards

If the application exposes a type library (and Microsoft Office applications do), then you can get at it from Microsoft C++ by 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 executable files.

To find out if an application exposes its functionality in this way, you'll probably need to consult the documentation for the specific application, because discovering (and understanding) type libraries is quite complicated.

The Windows SDK includes a tool, "OLE/COM Viewer" 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) give you a quick way to experiment. They're both capable of consuming OLE Automation interfaces.

By automate you mean be able to have a script that runs an application, communicates with it, and performs some functions. Something like an automated test script of sorts or something like that.

For that the simplest 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're developing an application then that becomes trickier, you could probably embed an existing scripting language into your executable and provide a way to interface into that. Perhaps have a command line option to automatically run a script within the context of your application. Or if you want to do some serious development work you could try adding in DCOM (I have not tried this so I don't know how much work is involved).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM