My goal is to call a very simple C++ program from python, see below. The program generates a couple of random numbers and then moves the mouse and clicks. I would like to be able to call it from python with a few inputs(the python side I understand), but i don't understand what I must add to the C++ code to allow it to accept these inputs.

Any help is greatly appreciated.

I'm not sure if this matters, but im using Bloodshed Dev-C++, on a mac within parallels.

here is the C++ code

#include <windows.h>
#include <ctime> 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE dummy, LPSTR lpCmdLine, int nShowCmd)
{
//Pixel Counts
int FoldX = 429;
int CCX = 559;
int BRX= 685;
int Width=90;
int Y1=526;
int Height=33;
srand((unsigned)time(0));
int XFudge=rand()%Width;
//Combine pixel count with the randomly generated number
srand((unsigned)time(0));
int YFudge=rand()%Height;
int X=FoldX+XFudge;
int Y=Y1+YFudge;
SetCursorPos(X,Y);

mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,
    X,
    Y,
    0,
    0
);
return 0;
  return 0;
}

from python i would like to be able to call this small app, but be able to change where the mouse clicks, i.e. change how X, and Y are defined.

The command-line arguments in WinMain programs are passed in the lpCmdLine argumenmt. Parse it just as you would any other white-space separated string

#include <string>
#include <iostream>
#include <sstream>
#include <vector>
...
...
	vector<string> parameters;
	if(lpCmdLine != NULL)
	{
		string word;
		stringstream str(lpCmdLine);
		while(str >> word)
			parameters.push_back(word);
	}

Or if you are just passing a couple integers then it simplifies to this:

#include <string>
#include <iostream>
#include <sstream>
#include <vector>
...
...
	int X = 0, Y = 0;
	if(lpCmdLine != NULL)
	{
		stringstream str(lpCmdLine);
                str >> X >> Y;
	}

Thank you very much for the response. when I added this code and compiled it I was given an error "24 `stringstream' undeclared (first use this function)"

I am very new to C++ so from this I gather I am missing some include...or my compiler does not support this? I really don't know what more to do?

Thanks in advanced

Use std::stringstream or using namespace std; Stringstreams are part of the std namespace. Dragon just forgot to insert it (old age, you know ;))

did you include <sstream> as illustrated in my previous example ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.