-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
150 lines (117 loc) · 3.93 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "Windows.h"
int MAXDEVNAMELENGTH = 100;
bool txtBox_text_toLPWSTR(QLineEdit *txtBox, LPWSTR outString)
{
int strlength = txtBox->text().length();
if (strlength > 0 && strlength < 100)
{
memset(outString,0,(strlength*2)+2);
int charArrayLen = txtBox->text().toWCharArray(outString);
if(strlength == charArrayLen)
{
return true;
}
}
return false;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btnOpenClose_clicked()
{
QPushButton *ptrbtnOpenClose = (QPushButton *)ui->btnOpenClose;
if (ptrbtnOpenClose->text() == "Open")
{
QLineEdit *ptrtxtBoxDeviceFileName = (QLineEdit *)ui->txtBoxDeviceFileName;
LPWSTR deviceName = new wchar_t[ptrtxtBoxDeviceFileName->text().length()*2];
if(txtBox_text_toLPWSTR(ptrtxtBoxDeviceFileName,deviceName))
{
MessageBox(NULL,deviceName,L"OpenDevice",0);
devHandle = CreateFile(deviceName,
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if(devHandle != INVALID_HANDLE_VALUE)
{
ptrtxtBoxDeviceFileName->setEnabled(false);
ptrbtnOpenClose->setText("Close");
QLineEdit *ptrtxtBoxIOCTL = (QLineEdit *)ui->txtBoxIOCTL;
ptrtxtBoxIOCTL->setEnabled(true);
}
else
{
DWORD errorCode = GetLastError();
LPWSTR ErrorMessage = NULL;
DWORD strLength = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, \
NULL, errorCode, 0, \
(LPWSTR)&ErrorMessage, 10,NULL);
//LPWSTR strErrorCode = new wchar_t[20];
//wsprintf(strErrorCode,L"%X",errorCode);
//MessageBox(NULL,strErrorCode,L"ERROR",0);
if (strLength > 0)
MessageBox(NULL,ErrorMessage,L"ERROR",0);
LocalFree(ErrorMessage);
//delete(strErrorCode);
}
}
delete(deviceName);
}
else
{
if(devHandle != NULL)
CloseHandle(devHandle);
ptrbtnOpenClose->setText("Open");
QLineEdit *ptrtxtBoxDeviceFileName = (QLineEdit *)ui->txtBoxDeviceFileName;
ptrtxtBoxDeviceFileName->setEnabled(true);
QWidget *ptrbtnSendIOCTL = (QWidget *) ui->btnSendIOCTL;
ptrbtnSendIOCTL->setEnabled(false);
QLineEdit *ptrtxtBoxIOCTL = (QLineEdit *)ui->txtBoxIOCTL;
ptrtxtBoxIOCTL->setEnabled(false);
}
}
void MainWindow::on_btnSendIOCTL_clicked()
{
QLineEdit *ptrtxtBoxIOCTL = (QLineEdit *)ui->txtBoxIOCTL;
LPWSTR strIOCTL = new wchar_t[ptrtxtBoxIOCTL->text().length()*2];
if(txtBox_text_toLPWSTR(ptrtxtBoxIOCTL, strIOCTL))
{
MessageBox(NULL,strIOCTL,L"TEST",0);
}
delete(strIOCTL);
}
void MainWindow::on_txtBoxDeviceFileName_textChanged(const QString &arg1)
{
QPushButton *ptrbtnOpenClose = (QPushButton *)ui->btnOpenClose;
if (arg1.length() > 0 && arg1.length() < MAXDEVNAMELENGTH)
{
ptrbtnOpenClose->setEnabled(true);
}
else
{
ptrbtnOpenClose->setEnabled(false);
}
}
void MainWindow::on_txtBoxIOCTL_textChanged(const QString &arg1)
{
QPushButton *ptrbtnSendIOCTL = (QPushButton *)ui->btnSendIOCTL;
if (arg1.length() > 0 && arg1.length() < MAXDEVNAMELENGTH)
{
ptrbtnSendIOCTL->setEnabled(true);
}
else
{
ptrbtnSendIOCTL->setEnabled(false);
}
}