-3

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();

    }
Raouia
  • 1
  • 2
  • 1
    Please post the complete error message as text. Just a picture with some red underlined text is not going to get you an answer. – Richard Critten Jun 06 '18 at 09:55
  • Actually, search for that error text first. There's almost certainly an existing answer. – MSalters Jun 06 '18 at 09:57
  • ther is the error sorry it's in frensh : " un membre d'une classe managé ne peut pas être d'un type de classe non managé " it's in the lines COPYDATASTRUCT cpd; cpd.dwData = 0; cpd.cbData = dataToSend.GetLength(); – Raouia Jun 06 '18 at 10:00
  • _" un membre d'une classe managé ne peut pas être d'un type de classe non managé "_: `a member of a managed class can not be of an unmanaged class type` – Richard Critten Jun 06 '18 at 10:04
  • including ```` should fix that problem – Asesh Jun 06 '18 at 10:35

1 Answers1

0

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;
VLL
  • 9,634
  • 1
  • 29
  • 54