Jump to content
Sign in to follow this  

Sending commands to PowerPro

Recommended Posts

Hi guys,

I'd like to send some commands to a running instance of PowerPro via AutoIt. This is the C/C++ (?) code that will achieve it:

#define VAR_SIZE 532
char szCommand[VAR_SIZE + 24];
char szName[VAR_SIZE + 1];

strcpy(szCommand, "Win.debug(?'Eeexcellent.')");
cd.dwData = 1;
cd.cbData = strlen(szCommand) + 1;
cd.lpData = szCommand;

g_hwndPowerPro = FindWindow("PowerProMain", NULL);
SendMessage(g_hwndPowerPro, WM_COPYDATA, 0, (LPARAM)&cd);

I think I can understand about half of this code enough to write its AutoIt equivalent, but I'm not sure about how I'd go about passing a COPYDATASTRUCT. For what it's worth, MSDN says this about the COPYDATASTRUCT structure:

typedef struct tagCOPYDATASTRUCT {
    ULONG_PTR dwData;
    DWORD cbData;
    PVOID lpData;

Using the above info and some reading I came up with the code below. Am I frightfully far off the mark? --

Global $WM_COPYDATA = 0x004A

Local $Command = "Win.debug(?'Eeexcellent.')"

Local $Struct = DLLStructCreate("ptr;dword;ptr")
DLLStructSetData($Struct, 1, 1)
DLLStructSetData($Struct, 2, StringLen($Command) + 1)
DLLStructSetData($Struct, 3, $Command)

Local $StructPtr = DLLStructGetPtr($Struct)
Local $WinHandle = WinGetHandle("PowerProMain")
DLLCall("user32.dll", "none", "SendMessage", "hWnd", $WinHandle, "int", $WM_COPYDATA, "ptr", $StructPtr)

Share this post

Link to post
Share on other sites

Thanks for the input Larry.

I notice that the COPYDATASTRUCT wants something called a PVOID. From what I can tell, this seems to be a pointer-type thing and in my case, I would want to give it a pointer to my string. I suppose I would need another DLLStruct for that. I'll see what I can do.

Share this post

Link to post
Share on other sites

Done! I've posted my work to the Scripts and Scraps forum.

Thanks very much for your help Larry! Please feel free to check it out in case I've done something drastically ugly -- I have no experience with DLLs, structures or C (yet).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...