0

I'm using Python2.7 and Visual Studio 2010 on Windows 7 Professional.

I'm trying to use SendMessage to send a copydatastruct object to a MFC C++ program. The C++ program receives the message fine, however, I cannot figure out the correct data type for the dwData attribute.

The dwData attribute is being checked against variables declared in the C++ code:

#define RUN_ASYNC 0x8001
#define RUN_SYNC 0x8002
...
#define RUN_MCS 0x8012
...

The OnCopyData function in the C++ code has a basic switch statement:

...
switch(pCopyDataStruct->dwData)
{
    case RUN_ASYNC:
        {
            // DO STUFF
        }
        break;
    case RUN_SYNC:
        {
            // DO STUFF
        }
        break;
    ...
    case RUN_MCS:
        {
            // DO STUFF
        }
        break;
    ...
    default:
        TRACE(_T("OnCopyData unknown function"))
        break;
}

Since I'm not sending it properly, it never hits the proper case and ends up using the default.

I'm setting up the copydatastruct in my python script as:

class COPYDATASTRUCT(Structure):
_fields_ = [("dwData", c_ulong),
            ("cbData", c_uint),
            ("lpData", c_void_p)]

and declaring the variables as:

RUN_ASYNC = 8001
RUN_SYNC = 8002
...
RUN_MCS = 8012
...

This sends the correct four digit number to the C++ program, but it's not being recognized properly for the switch case.

When I declared the variables in the python script as:

RUN_ASYNC = 0x8001
RUN_SYNC = 0x8002
...
RUN_MCS = 0x8012
...

The C++ program receives a number like 32786 that, of course, doesn't work with the switch statement.

How do I need to declare the variables that I'm going to be sending to the C++ program in the dwData attribute to get them to work with the C++ code. I have a feeling that I'm being really stupid, and missing something relatively simple.

Thanks in advance.

  • FWIW: 32786 is 0x8012. is that one of the values in the "..." section of your code? – Dale Wilson Aug 22 '13 at 17:29
  • Have you tried it with 0x8001 and 0x8002? 32786 is 0x8012 (not sure where the extra bits came from, though). – tdelaney Aug 22 '13 at 17:30
  • Yes, 0x8012 is one of the other options. Sorry about missing that. None of the options work with the switch statement. – timdoughty Aug 22 '13 at 17:33
  • But that's the thing. 32786 is 0x8012 which is RUN_MCS and does work with the switch statement. – tdelaney Aug 22 '13 at 17:40
  • Well, I can honestly say I'm really confused, because it's working now. Only adjustment I made was to switch the numbers back to hex in the python code. Thank you for the help, I'll show myself over to the "Why is it working now?" corner. – timdoughty Aug 22 '13 at 17:57
  • It must have been the do_remove_gremlins() call. – tdelaney Aug 22 '13 at 18:09
  • That's what I'm thinking :) – timdoughty Aug 22 '13 at 18:18
  • Not an issue here, but `dwData` is [a `ULONG_PTR`](http://msdn.microsoft.com/en-us/library/ms649010) nowadays. I'd use `c_size_t` or `wintypes.WPARAM`. – Eryk Sun Aug 22 '13 at 18:32

0 Answers0