【问题标题】:COPYDATASTRUCT, WM_COPYDATA复制数据结构,WM_COPYDATA
【发布时间】:2018-06-06 09:52:40
【问题描述】:

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

这是错误:

代码如下:

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

    }

【问题讨论】:

  • 请将完整的错误消息以文本形式发布。只是一张带有红色下划线文字的图片不会给你答案。
  • 其实先搜索那个错误文本。几乎肯定有一个现成的答案。
  • 有错误对不起它在法语中:“ un membre d'une classe managé ne peut pas être d'un type de classe non managé”它在 COPYDATASTRUCT cpd 行中; cpd.dwData = 0; cpd.cbData = dataToSend.GetLength();
  • " un member 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
  • 包括&lt;windows.h&gt; 应该可以解决这个问题

标签: c++ string sendmessage wm-copydata


【解决方案1】:

有几个问题:

您是在定义一个类型,而不是创建一个变量。将行 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多