tags:

views:

255

answers:

2

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

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

Regards

A: 

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).

Daemin
Firstly, thanks for your response. I believe I meant (excuse my lack of understanding - currently on COM access), access functionality available by an existing application. Basically, from a C/C++ app call COM functionality.Regards
Aaron
So you want to know how to call functions on COM objects (in other applications) using C++ in your current application?
Daemin
Hi Daemin, thanks for your reply - I'm grateful. Actually - Yes. I am an intermediate Linux C programmer (don't mind using C++, but rather C) who lacks windows programming experience. However, I can do it - just need some guidance - regards :)
Aaron
Okay, I'd change my answer or add a new one, but the answer you selected is very good. Good luck!
Daemin
Hi Daemin, I found an [http://support.microsoft.com/kb/181473] article - Use OLE Automation from a C Application Rather Than C++. Would this be applicable or something/method that you would recommend? Regards :)
Aaron
Yeah, that looks reasonable, you're still essentially programming in C++ but in a C way using a struct of function pointers and passing in the "this" pointer explicitly. If you really want to just use C then go ahead, but I'd suggest trying C++ for this purpose.
Daemin
+3  A: 

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.

Roger Lipscombe
Perfect! Thanks a lot Roger :) The application, I'm attempting to exploit is called Simul8 - access COM from C++/C application that I'm writing - regards :)
Aaron