freekill
10th February 2010, 13:01
I have a working code in dev-c++ where I'm transmitting from a host PC to a mobile robot using bluetooth. However, I'm getting errors when I try to integrate the working program into my Qt GUI. I'm getting this particular error:
In member function 'void Bluetooth::initialize()': error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'
Here's my code:
bluetooth.h
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
#include <windows.h>
class Bluetooth {
public:
Bluetooth();
~Bluetooth();
void initialize();
void transmit(int right, int left);
private:
DWORD bytes_written;
BOOL Status;
HANDLE SerialHandle;
DCB SerialConfigs;
};
#endif
bluetooth.cpp
#include <QDebug>
#include "bluetooth.h"
#include "settings.h"
Bluetooth::Bluetooth() {}
Bluetooth::~Bluetooth() {}
void Bluetooth::initialize() {
qDebug()<<"Initializing BlueTooth...";
Status = 0;
SerialHandle = CreateFile("COM5",
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(SerialHandle==INVALID_HANDLE_VALUE) {
if(GetLastError()==ERROR_FILE_NOT_FOUND) {
qDebug()<<"E: Serial Port Does Not Exist!";
}
qDebug()<<"An Error Occured!";
}
ZeroMemory(&SerialConfigs, sizeof(SerialConfigs));
SerialConfigs.DCBlength = sizeof(SerialConfigs);
if (!GetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<< "Error Getting State!";
}
SerialConfigs.BaudRate = CBR_9600;
SerialConfigs.ByteSize = 8;
SerialConfigs.StopBits = ONESTOPBIT;
SerialConfigs.Parity = NOPARITY;
if(!SetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<<"Error Setting Serial Port State!";
}
qDebug()<<"Initialization Done";
}
void Bluetooth::transmit(int right, int left) {
WriteFile(SerialHandle,
&right, // Outgoing data
1, // Number of bytes to write
&bytes_written, // Number of bytes written
NULL);
Status = WriteFile(SerialHandle,
&left,
1,
&bytes_written,
NULL);
if (Status == 0) {
qDebug()<<"Error Writing";
}
}
In member function 'void Bluetooth::initialize()': error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'
Here's my code:
bluetooth.h
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
#include <windows.h>
class Bluetooth {
public:
Bluetooth();
~Bluetooth();
void initialize();
void transmit(int right, int left);
private:
DWORD bytes_written;
BOOL Status;
HANDLE SerialHandle;
DCB SerialConfigs;
};
#endif
bluetooth.cpp
#include <QDebug>
#include "bluetooth.h"
#include "settings.h"
Bluetooth::Bluetooth() {}
Bluetooth::~Bluetooth() {}
void Bluetooth::initialize() {
qDebug()<<"Initializing BlueTooth...";
Status = 0;
SerialHandle = CreateFile("COM5",
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(SerialHandle==INVALID_HANDLE_VALUE) {
if(GetLastError()==ERROR_FILE_NOT_FOUND) {
qDebug()<<"E: Serial Port Does Not Exist!";
}
qDebug()<<"An Error Occured!";
}
ZeroMemory(&SerialConfigs, sizeof(SerialConfigs));
SerialConfigs.DCBlength = sizeof(SerialConfigs);
if (!GetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<< "Error Getting State!";
}
SerialConfigs.BaudRate = CBR_9600;
SerialConfigs.ByteSize = 8;
SerialConfigs.StopBits = ONESTOPBIT;
SerialConfigs.Parity = NOPARITY;
if(!SetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<<"Error Setting Serial Port State!";
}
qDebug()<<"Initialization Done";
}
void Bluetooth::transmit(int right, int left) {
WriteFile(SerialHandle,
&right, // Outgoing data
1, // Number of bytes to write
&bytes_written, // Number of bytes written
NULL);
Status = WriteFile(SerialHandle,
&left,
1,
&bytes_written,
NULL);
if (Status == 0) {
qDebug()<<"Error Writing";
}
}