未解决的链接错误

时间:2013-02-06 16:18:09

标签: c++ function mfc dialog lnk2019

我在尝试编译时收到此错误。

error LNK2019: unresolved external symbol "public: void __thiscall Serial::WritePort(char * const)" (?WritePort@Serial@@QAEXQAD@Z) referenced in function "public: void __thiscall CThermotronDlg::OnBnClickedButton2(void)" (?OnBnClickedButton2@CThermotronDlg@@QAEXXZ)

我已经包含了所有必需的头文件但是当我尝试在我的主对话框中调用我的WritePort函数(位于我的sConfig.cpp中)时,我收到此链接错误。此外,每个.cpp文件都在同一个文件夹中,所以我不想在下面的不同位置引用文件,这是WritePort函数和调用它的块。

写端口

void WritePort(char buffer[])
{

HANDLE sSerial = CreateFile(L"COM3",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
OpenPort();
DWORD bytes;
WriteFile(sSerial, buffer,sizeof(buffer),&bytes,NULL);
}

void CThermotronDlg::OnBnClickedButton2()

{

CString str; str.Format(L"%d",Index);
LPTSTR Dwell = new TCHAR[1000];
USES_CONVERSION;
char* buffer =T2A(Dwell);
MyListEx.GetItemText(Index,1,Dwell,1000);

Serial Port;
Port.WritePort(buffer);


AfxMessageBox(Dwell,MB_OK,NULL);

}

2 个答案:

答案 0 :(得分:2)

应该不是

void WritePort(char buffer[])

void Serial::WritePort(char buffer[])

答案 1 :(得分:1)

函数WritePort需要成为Serial类的一部分,因为您将其用作Port.WritePort(buffer)而不是WritePort(buffer)

void Serial::WritePort(char buffer[])
{
bool umm;
HANDLE sSerial = CreateFile(L"COM3",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
OpenPort();
DWORD bytes;
umm = WriteFile(sSerial, buffer,sizeof(buffer),&bytes,NULL);
}