COPYDATASTRUCT, WM_COPYDATA

711 Views Asked by At

I'm trying to send Data between two programs using WM_COPYDATA but i have a problem in the definition of COPYDATASTRUCT;

Here is the error:

enter image description here

Here's the code:

#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

There are 1 best solutions below

0
On

There are several issues:

You are defining a type, not creating a variable. Change line typedef struct COPYDATASTRUCT cpd; to COPYDATASTRUCT cpd;.

You cannot execute code in the class definition. You should move these lines into a function:

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

You don't need to define COPYDATASTRUCT in your program. It is defined in windows.h. Remove this:

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