USB に接続されたマウスからすべての信号を読み取る単純なコンソール プログラムを作成しようとしていました。私は問題に直面しました: GetCommState(nCom, &dcb) は常にゼロを返します。これは私の仕事にはあまり役に立ちません。コードは次のとおりです。
int _tmain(int argc, TCHAR *argv[]) {
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
TCHAR *pcCommPort = TEXT("\\\\.\\HCD0"); // USB name
// Open a handle to the specified com port.
hCom = CreateFile(pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // default security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL); // hTemplate must be NULL for comm devices
if (hCom == INVALID_HANDLE_VALUE) {
// Handle the error.
printf("CreateFile failed with error %d.\n", GetLastError());
Sleep(15000);
return (1);
}
// Initialize the DCB structure.
SecureZeroMemory(&dcb, sizeof(DCB));
dcb.DCBlength = sizeof(DCB);
// Build on the current configuration by first retrieving all current
// settings.
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess) {
// Handle the error.
printf("GetCommState failed with error %s.\n", GetLastError());
printf("Cannot get first time");
Sleep(12000);
return (2);
}
.......
GetLastError() は 1 を返しますが、この問題に潜んでいても結果は得られませんでした。
これは単に msdn の例からのコピーペーストですが、私にはうまくいきませんでした。
教えてください: 0 以外の値を返すようにするには、何を変更すればよいでしょうか。タスクの別の部分に進むことができます。