[問題] handle
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
BCB6
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
第一次用WIN32 API, 照書打...
hComm一直等於INVALID_HANDLE_VALUE,為什麼呢?
我有確認RS232是COM1沒錯,Edit也是1
我有哪邊弄錯了嗎?
後面還有一些CODE我沒貼, 因為hComm沒成功, 後面就沒意義了!
餵入的資料(Input):
預期的正確結果(Expected Output):
不出現 Open Serial Port Error
錯誤結果(Wrong Output):
出現 Open Serial Port Error
程式碼(Code):(請善用置底文網頁, 記得排版)
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE hComm;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *ComNo;
DCB dcb;
String Temp;
Temp = "COM" + IntToStr(ComboBox1->ItemIndex + 1);
ComNo = Temp.c_str();
hComm = CreateFile(ComNo,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
0);
if (hComm == INVALID_HANDLE_VALUE){
MessageBox(0,
"Open Serial Port Error",
"Comm Error",
MB_OK);
Edit1->Text = ComboBox1->ItemIndex + 1;
return;
}
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.225.85
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1473090974.A.F97.html
→
09/05 23:59, , 1F
09/05 23:59, 1F
※ 編輯: GooLoo (111.251.225.85), 09/06/2016 00:05:15
→
09/06 00:06, , 2F
09/06 00:06, 2F
→
09/06 01:31, , 3F
09/06 01:31, 3F
→
09/06 18:57, , 4F
09/06 18:57, 4F