I write a project with visual studio. In the project I build a class called CSimApplianceDlg which has two members:
static UINT RecvDataFrame(LPVOID pParam) and 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 has a public member function WriteToPort to send data through serial port.
public:
void WriteToPort(char* string);
void WriteToPort(char* string,int n);
void WriteToPort(LPCTSTR string);
void WriteToPort(LPCTSTR string,int n);
I called
m_Port.WriteToPort(m_SendData,len);
in UINT CSimApplianceDlg::RecvDataFrame(LPVOID pParam). However, while building the project, just at the line of the calling, I got
1>e:\mysourcecode\smarthome\simappliance\simappliance\simappliancedlg.cpp(557) : error C2228: left of '.WriteToPort' must have class/struct/union
1>e:\mysourcecode\smarthome\simappliance\simappliance\simappliancedlg.cpp(557) : error C2597: illegal reference to non-static member 'CSimApplianceDlg::m_SendData'
1>e:\mysourcecode\smarthome\simappliance\simappliance\simappliancedlg.cpp(557) : error C2597: illegal reference to non-static member 'CSimApplianceDlg::len'
How can I deal with these errors? And which WriteToPort is called, because I
am not familiar with LPCTSTR.
The function static UINT RecvDataFrame(LPVOID pParam) is static. It means you can call it without an instantiation of the object CSimApplianceDlg. In other words you can call CSimApplianceDlg::RecvDataFrame() from anywhere which is often the case for call back function. This means that within that function, you cannot access the member variables (m_Port). As pointed earlier, we do not have enough information to help but it's likely that the pParam passed has a pointer to the object... alternatively, if it's the only window in your app, you can try AfxGetMainWnd(). LPCTSTR is simply defined as const TCHAR *, where TCHAR is a char or a wchar_t if your are in ANSI or Unicode. Good luck!