COPYDATASTRUCT,WM_COPYDATA

时间:2018-06-06 09:52:41

标签: c++ string sendmessage wm-copydata

我尝试使用WM_COPYDATA在两个程序之间发送数据,但我在COPYDATASTRUCT的定义中遇到问题;

这是错误:

enter image description here

以下是代码:

#include <iostream>
#include <Windows.h>
#include <string>
#include <stdio.h>
#include <tchar.h>
#include < stdlib.h >  
#include < vcclr.h >
#include <msclr\marshal.h>
#include "MyForm.h"


namespace TestGraphique {

using namespace System;
using namespace msclr::interop;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Xml;
using namespace std;
typedef struct tagCOPYDATASTRUCT {
    ULONG_PTR dwData;
    DWORD     cbData;
    PVOID     lpData;
} COPYDATASTRUCT;


/// <summary>
/// Description résumée de MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:


    typedef struct COPYDATASTRUCT cpd;
     cpd.dwData = 0; // there is the problem
     cpd.cbData = dataToSend.GetLength(); // there is the problem 
    LPTSTR pszMem = new TCHAR[10000];
    HWND hWnd;
    HWND hWnd1;
    HWND hWnd2;
    HWND hWnd3;
    String^ a = "";
    String^ b = "";
    String^ c = "";
    String^ d = "";
    String^ result="";
    String^ TABLE = "";


    MyForm(void)
    {
        InitializeComponent();

    }

1 个答案:

答案 0 :(得分:0)

有几个问题:

您正在定义类型,而不是创建变量。将第typedef struct COPYDATASTRUCT cpd;行更改为COPYDATASTRUCT cpd;

您无法在类定义中执行代码。您应该将这些行移动到一个函数中:

cpd.dwData = 0;
cpd.cbData = dataToSend.GetLength();

您无需在程序中定义COPYDATASTRUCT。它在windows.h中定义。删除它:

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