我正在尝试将poCopyData
(PCOPYDATASTRUCT
)更改为字符串,也是将字符串转换回字符串的方法。所以我可以发送它,poCopyData
是程序将来自另一个程序的消息复制到的地方。
PCOPYDATASTRUCT poCopyData = (PCOPYDATASTRUCT)ulParam;
// Note this is just outputs the message i don't how it converts it.
printf("Message (%u): %.*s\n", poCopyData->dwData, poCopyData->cbData, poCopyData->lpData);
答案 0 :(得分:1)
inline LRESULT CopyData( HWND hwnd, DWORD message, const char* str )
{
COPYDATASTRUCT copy_data = { message, strlen( str ) + 1, str };
return SendMessage( hwnd, WM_COPYDATA, 0, reinterpret_cast< LPARAM >( ©_data ) );
}
LRESULT WINAPI WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
if( message == WM_COPYDATA )
{
COPYDATASTRUCT* copy_data = reinterpret_cast< COPYDATASTRUCT* >( lparam );
const char* str = reinterpret_cast< const char* >( copy_data.lpData );
printf( "Message (%u): %.*s\n", copy_data->dwData, str );
}