communicating with other apps. in VC++

In VBA there is a way to communicate with other
applications via the SendKeys command, is it possible to
implement a similar function in Visual C++?
How about "Shell" and "AppActivate"?
Who is Participating?
fasterConnect With a Mentor Commented:
First, use FindWindow() to get the window handle of calc.  Then use SendMessage() to send key strokes.

hwnd=FindWindow(NULL, "Calculator");
SendMessage(hwnd, WM_CHAR, wparam, lparam);

Refer to SDK help for wparam and lparam.
C can do anything VB or VBA can do.

I don't know the SendKeys command, but I guess it simply send some WM_KEYDOWN/WM_KEYUP messages.  In c, you can call SendMessage(), which can not only send key messages but also a lot of others.

You can also use OLE, DDE, socket etc to communicate with other processes.
quillerAuthor Commented:
I should be a little more specific.  Say, I want to communicate
with an App. that has no OLE,DDE, or any other support that
I know of.  Under Unix, I used "expect".  Under VBA, there is
the "SendKeys" command.  I want to be able to send keys to
another app.  I'm basically trying to set up a batch procedure
which at one step involves calling an App. that has no msg.
support.  So, for example, I can do the following in VBA:

Sub Send_Msg()
 Dim i, Msg, x                             ' Declare variables.
 x = Shell("C:\WINNT\system32\calc.exe", 1)  ' open Calculator.
 For i = 1 To 10                        ' Set up counting loop.
  SendKeys i, True         ' Send keystrokes to the calculator.
  SendKeys "{+}", True
 Next i                               ' to add each value of I.
 AppActivate "Microsoft Access"          ' Return focus to VBA.
 Msg = "Choose OK to close Calculator."  ' Stop to see results.
 MsgBox Msg
 AppActivate "calculator"         ' Return focus to Calculator.
 SendKeys "%{F4}", True      ' Send Alt+F4 to close Calculator.
 AppActivate "Microsoft Access" ' Return focus to VBA
End Sub

So, how can I do the equivalent from Visual C++?

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Use the system() command to execute programs from within vc++. Like this: system("executable.exe")
quillerAuthor Commented:
The system command I am aware of.  But how do I target a
specific window, as in the above example (I can target the
window by its name, "calculator"), and how do I send key strokes
to it.

quillerAuthor Commented:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.