2017-05-15 17 views
-2

Visual Studio로 프로젝트를 씁니다. 공용 멤버 함수를 WriteToPort은 시리얼 포트를 통해 데이터를 보낼 수있다C++ 클래스 정적 멤버 함수 호출 오류

static UINT RecvDataFrame(LPVOID pParam)

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 
...... 

CSerialPortCSerialPort m_Port : 프로젝트에서 나는 두 멤버가 CSimApplianceDlg라는 클래스를 구축 할 수 있습니다.

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

나는 UINT CSimApplianceDlg :: RecvDataFrame (LPVOID pParam)에

m_Port.WriteToPort(m_SendData,len);

을했다. 단지 호출의 라인에서 프로젝트를 구축하는 동안 그러나, 나는 가지고

1> E : \ mysourcecode \ smarthome \ simappliance \ simappliance \ simappliancedlg.cpp (557) : 오류 C2228은 '왼쪽 CSimApplianceDlg :: m_SendData '
.WriteToPort는'\ mysourcecode \ smarthome \ simappliance \ simappliance \ simappliancedlg.cpp (557) : 오류 C2597 비 정적 멤버 불법 참조 클래스/구조체/노동 조합
1> 전자 있어야합니다 ' 1> e : \ mysourcecode \ smarthome \ simappliance \ simappliance \ simappliancedlg.cpp (557) : C2597 오류 : 비 정적 멤버 'CSimApplianceDlg :: len'에 대한 잘못된 참조

어떻게 이러한 오류를 처리 할 수 ​​있습니까? 그리고 내가 LPCTSTR에 익숙하지 않기 때문에 어느 WriteToPort이 호출됩니다.

+2

오류가 발생한 코드를 표시하는 것을 잊었습니다. –

+0

아마도'CSerialPort' 클래스의 * 인스턴스 * 생성에 실패했습니다. Michael이 말했듯이, 실제 코드를 볼 수 없다면 확실하게 말할 수 없습니다. 질문을 [mcve]로 업데이트하십시오. –

+0

"m_Port.WriteToPort (m_SendData, len);"호출시 오류가 발생했습니다. – pellyhawk

답변

0

기능 정적 UINT RecvDataFrame (LPVOID pParam)은 정적입니다. 즉, 개체 CSimApplianceDlg의 인스턴스화없이 호출 할 수 있습니다. 즉, 콜백 함수의 경우에 흔히있는 CSimApplianceDlg :: RecvDataFrame()을 호출 할 수 있습니다. 이는 해당 함수 내에서 멤버 변수 (m_Port)에 액세스 할 수 없음을 의미합니다. 앞에서 지적했듯이, 우리는 도움이 될만한 정보가 없지만 전달 된 pParam이 객체에 대한 포인터를 가지고있을 가능성이 있습니다 ... 아니면, 응용 프로그램의 유일한 창인 경우 AfxGetMainWnd()를 시도해보십시오. LPCTSTR은 단순히 const TCHAR *로 정의됩니다. 여기서 TCHAR은 ANSI 또는 유니 코드 인 경우 인 경우 char 또는 wchar_t입니다. 행운을 빕니다!