-2

我用视觉工作室写了一个项目。在项目中,我构建了一个名为 CSimApplianceDlg 的类,它有两个成员:

static UINT RecvDataFrame(LPVOID pParam)CSerialPort m_Port

class CSimApplianceDlg : public CDialog
{
// Construction
public:
CSimApplianceDlg(CWnd* pParent = NULL); // standard constructor

// Implementation
protected:
HICON m_hIcon;

// Added for Serial Port operation
static UINT RecvDataFrame(LPVOID pParam); // Process received data
......
private:
......
unsigned char m_SendData[MAX_LEN]; // Data to be sent
int len;                           // the length of data to be sent
public:
CSerialPort m_Port;     // CSerialPort Object
......

CSerialPort有一个公共成员函数WriteToPort通过串口发送数据。

public:
void      WriteToPort(char* string);
void      WriteToPort(char* string,int n);
void      WriteToPort(LPCTSTR string);
void      WriteToPort(LPCTSTR string,int n);

我打了电话

m_Port.WriteToPort(m_SendData,len);

在 UINT CSimApplianceDlg::RecvDataFrame(LPVOID pParam) 中。但是,在构建项目时,就在调用的那一行,我得到了

1>e:\mysourcecode\smarthome\simappliance\simappliance\simappliancedlg.cpp(557):错误 C2228:'.WriteToPort' 左侧必须有类/结构/联合
1>e:\mysourcecode\smarthome\simappliance\simappliance\simappliancedlg .cpp(557) : 错误 C2597: 非法引用非静态成员 'CSimApplianceDlg::m_SendData'
1>e:\mysourcecode\smarthome\simappliance\simappliance\simappliancedlg.cpp(557) : 错误 C2597: 非法引用非静态成员 'CSimApplianceDlg::len'

我该如何处理这些错误?并且WriteToPort被称为,因为我不熟悉LPCTSTR

4

1 回答 1

0

函数 static UINT RecvDataFrame(LPVOID pParam) 是静态的。这意味着您可以在不实例化对象 CSimApplianceDlg 的情况下调用它。换句话说,您可以从任何地方调用 CSimApplianceDlg::RecvDataFrame() ,这通常是回调函数的情况。这意味着在该函数中,您无法访问成员变量 (m_Port)。如前所述,我们没有足够的信息来提供帮助,但传递的 pParam 可能有一个指向该对象的指针……或者,如果它是您应用程序中的唯一窗口,您可以尝试 AfxGetMainWnd()。LPCTSTR 被简单地定义为 const TCHAR *,如果您使用 ANSI 或 Unicode,则 TCHAR 是 char 或 wchar_t。祝你好运!

于 2017-05-16T07:02:26.037 回答