Made the driver build on windows, still not working though.

This commit is contained in:
Micke Prag 2008-03-02 16:58:01 +00:00
parent 269393cf04
commit 858c772c12
5 changed files with 97 additions and 84 deletions

View file

@ -218,7 +218,7 @@ bool WINAPI devSetModel(int intDeviceId, char* strNewModel){
return blnSuccess; return blnSuccess;
} }
bool WINAPI devSetArguments(int intDeviceId, char* strArguments){ /*bool WINAPI devSetArguments(int intDeviceId, char* strArguments){
vector <int> vArguments; vector <int> vArguments;
//int intArguments[] = new int[]; //bort? //int intArguments[] = new int[]; //bort?
@ -236,7 +236,7 @@ bool WINAPI devSetArguments(int intDeviceId, char* strArguments){
handleException(e); handleException(e);
return false; return false;
} }
} }*/
int WINAPI devGetArgument(int intDeviceId, int intArgumentIndex){ int WINAPI devGetArgument(int intDeviceId, int intArgumentIndex){
int intReturn; int intReturn;

View file

@ -12,7 +12,7 @@ EXPORTS
devSetName @8 devSetName @8
devSetVendor @9 devSetVendor @9
devSetModel @10 devSetModel @10
devSetArguments @11 ; devSetArguments @11
devAddDevice @12 devAddDevice @12
devRemoveDevice @13 devRemoveDevice @13

View file

@ -179,10 +179,6 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
> >
<File
RelativePath=".\Device.cpp"
>
</File>
<File <File
RelativePath=".\win\Device.cpp" RelativePath=".\win\Device.cpp"
> >
@ -205,6 +201,10 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\Device.cpp"
>
</File>
<File <File
RelativePath=".\DeviceIkea.cpp" RelativePath=".\DeviceIkea.cpp"
> >
@ -226,7 +226,11 @@
> >
</File> </File>
<File <File
RelativePath=".\TelldusSettings.cpp" RelativePath=".\settings\TelldusSettings.cpp"
>
</File>
<File
RelativePath=".\settings\TelldusSettingsWinRegistry.cpp"
> >
</File> </File>
<File <File
@ -272,7 +276,7 @@
> >
</File> </File>
<File <File
RelativePath=".\TelldusSettings.h" RelativePath=".\settings\TelldusSettings.h"
> >
</File> </File>
<File <File

View file

@ -2,7 +2,7 @@
#define TELLDUSSETTINGS_H #define TELLDUSSETTINGS_H
#include "../Device.h" #include "../Device.h"
#include <vector.h> //#include <vector>
class privateVars; class privateVars;
@ -20,7 +20,7 @@ public:
char* getModel(int intDeviceId); char* getModel(int intDeviceId);
bool setModel(int intDeviceId, char* strModel); bool setModel(int intDeviceId, char* strModel);
int* getArguments(int intDeviceId); int* getArguments(int intDeviceId);
bool setArguments(int intDeviceId, vector <int> vArguments); // bool setArguments(int intDeviceId, vector <int> vArguments);
int addDevice(); int addDevice();
int getDeviceId(int intDeviceIndex); int getDeviceId(int intDeviceIndex);
bool removeDevice(int intDeviceId); bool removeDevice(int intDeviceId);

View file

@ -1,4 +1,4 @@
#include "StdAfx.h" #include "../StdAfx.h"
#include "TelldusSettings.h" #include "TelldusSettings.h"
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -8,15 +8,24 @@
using namespace std; using namespace std;
class privateVars {
public:
HKEY hk;
std::string strRegPathDevice;
std::string strRegPath;
int intMaxRegValueLength;
};
/* /*
* Constructor * Constructor
*/ */
TelldusSettings::TelldusSettings(void) TelldusSettings::TelldusSettings(void)
{ {
strRegPathDevice = "SOFTWARE\\Telldus\\Devices\\"; d = new privateVars();
strRegPath = "SOFTWARE\\Telldus\\"; d->strRegPathDevice = "SOFTWARE\\Telldus\\Devices\\";
d->strRegPath = "SOFTWARE\\Telldus\\";
intMaxRegValueLength = 1000; d->intMaxRegValueLength = 1000;
} }
/* /*
@ -25,9 +34,9 @@ TelldusSettings::TelldusSettings(void)
TelldusSettings::~TelldusSettings(void) TelldusSettings::~TelldusSettings(void)
{ {
//RegCloseKey(hk); //close all, if still open //TODO: Need some way to know if open or closed //RegCloseKey(hk); //close all, if still open //TODO: Need some way to know if open or closed
strRegPath = ""; d->strRegPath = "";
strRegPathDevice = ""; d->strRegPathDevice = "";
intMaxRegValueLength = -1; d->intMaxRegValueLength = -1;
} }
@ -40,17 +49,17 @@ int TelldusSettings::getNumberOfDevices(void){
try{ try{
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, d->strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
string strNumSubKeys; string strNumSubKeys;
DWORD dNumSubKeys; DWORD dNumSubKeys;
RegQueryInfoKey(hk, NULL, NULL, NULL, &dNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); RegQueryInfoKey(d->hk, NULL, NULL, NULL, &dNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
intNumberOfDevices = (int)dNumSubKeys; intNumberOfDevices = (int)dNumSubKeys;
RegCloseKey(hk); RegCloseKey(d->hk);
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
@ -90,25 +99,25 @@ char* TelldusSettings::getName(int intDeviceId){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
DWORD dwLength; DWORD dwLength;
char* Buff = new char[intMaxRegValueLength]; char* Buff = new char[d->intMaxRegValueLength];
long lngStatus = RegQueryValueEx(hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength); long lngStatus = RegQueryValueEx(d->hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength);
if(lngStatus == ERROR_MORE_DATA){ if(lngStatus == ERROR_MORE_DATA){
Buff = new char[dwLength]; Buff = new char[dwLength];
lngStatus = RegQueryValueEx(hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength); lngStatus = RegQueryValueEx(d->hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength);
} }
strReturn = Buff; strReturn = Buff;
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
strReturn = ""; strReturn = "";
@ -125,18 +134,18 @@ bool TelldusSettings::setName(int intDeviceId, char* strNewName){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
intMaxRegValueLength = (int)strlen(strNewName); d->intMaxRegValueLength = (int)strlen(strNewName);
RegSetValueEx(hk, "Name", 0, REG_SZ, (LPBYTE)strNewName, intMaxRegValueLength); RegSetValueEx(d->hk, "Name", 0, REG_SZ, (LPBYTE)strNewName, d->intMaxRegValueLength);
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
@ -154,18 +163,18 @@ char* TelldusSettings::getVendor(int intDeviceId){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, (LPCSTR)strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, (LPCSTR)strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
DWORD dwLength; DWORD dwLength;
char* Buff = new char[intMaxRegValueLength]; char* Buff = new char[d->intMaxRegValueLength];
long lngStatus = RegQueryValueEx(hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength); long lngStatus = RegQueryValueEx(d->hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength);
if(lngStatus == ERROR_MORE_DATA){ if(lngStatus == ERROR_MORE_DATA){
Buff = new char[dwLength]; Buff = new char[dwLength];
lngStatus = RegQueryValueEx(hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength); lngStatus = RegQueryValueEx(d->hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength);
} }
strReturn = Buff; strReturn = Buff;
@ -173,7 +182,7 @@ char* TelldusSettings::getVendor(int intDeviceId){
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(exception e){ catch(exception e){
strReturn = ""; strReturn = "";
@ -195,18 +204,18 @@ bool TelldusSettings::setVendor(int intDeviceId, char* strVendor){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
intMaxRegValueLength = (int)strlen(strVendor); d->intMaxRegValueLength = (int)strlen(strVendor);
RegSetValueEx(hk, "Vendor", 0, REG_SZ, (LPBYTE)strVendor, intMaxRegValueLength); RegSetValueEx(d->hk, "Vendor", 0, REG_SZ, (LPBYTE)strVendor, d->intMaxRegValueLength);
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
blnSuccess = false; blnSuccess = false;
@ -223,26 +232,26 @@ char* TelldusSettings::getModel(int intDeviceId){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
DWORD dwLength; DWORD dwLength;
char* Buff = new char[intMaxRegValueLength]; char* Buff = new char[d->intMaxRegValueLength];
long lngStatus = RegQueryValueEx(hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength); long lngStatus = RegQueryValueEx(d->hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength);
if(lngStatus == ERROR_MORE_DATA){ if(lngStatus == ERROR_MORE_DATA){
Buff = new char[dwLength]; Buff = new char[dwLength];
lngStatus = RegQueryValueEx(hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength); lngStatus = RegQueryValueEx(d->hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength);
} }
strReturn = Buff; strReturn = Buff;
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
strReturn = ""; strReturn = "";
@ -259,18 +268,18 @@ bool TelldusSettings::setModel(int intDeviceId, char* strVendor){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
intMaxRegValueLength = (int)strlen(strVendor); d->intMaxRegValueLength = (int)strlen(strVendor);
RegSetValueEx(hk, "Model", 0, REG_SZ, (LPBYTE)strVendor, intMaxRegValueLength); RegSetValueEx(d->hk, "Model", 0, REG_SZ, (LPBYTE)strVendor, d->intMaxRegValueLength);
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
blnSuccess = false; blnSuccess = false;
@ -283,19 +292,19 @@ int TelldusSettings::getDeviceId(int intDeviceIndex){
try{ try{
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strRegPathDevice.c_str(), 0, KEY_READ, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, d->strRegPathDevice.c_str(), 0, KEY_READ, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
char* Buff = new char[intMaxRegValueLength]; char* Buff = new char[d->intMaxRegValueLength];
DWORD size; DWORD size;
if (RegEnumKeyEx(hk, intDeviceIndex, (LPSTR)Buff, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { if (RegEnumKeyEx(d->hk, intDeviceIndex, (LPSTR)Buff, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
intReturn = (int)_atoi64(Buff); intReturn = (int)_atoi64(Buff);
} }
delete Buff; delete Buff;
RegCloseKey(hk); RegCloseKey(d->hk);
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
@ -317,19 +326,19 @@ int TelldusSettings::getNumberOfArguments(int intDeviceId){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
DWORD dNumValues; DWORD dNumValues;
RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL); RegQueryInfoKey(d->hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL);
intReturn = (int)dNumValues - 3; //total number of values - model, name and vendor intReturn = (int)dNumValues - 3; //total number of values - model, name and vendor
} }
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
//error management //error management
@ -347,13 +356,13 @@ int* TelldusSettings::getArguments(int intDeviceId){
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
DWORD dNumValues; DWORD dNumValues;
RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL); RegQueryInfoKey(d->hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL);
int intNumberOfArguments = (int)dNumValues - 3; //total number of values - model, name and vendor int intNumberOfArguments = (int)dNumValues - 3; //total number of values - model, name and vendor
DWORD dwLength; DWORD dwLength;
@ -362,12 +371,12 @@ int* TelldusSettings::getArguments(int intDeviceId){
while(i < intNumberOfArguments){ while(i < intNumberOfArguments){
char* Buff = new char[intMaxRegValueLength]; char* Buff = new char[d->intMaxRegValueLength];
_itoa(i, chConvertBuffer, 10); _itoa(i, chConvertBuffer, 10);
long lngStatus = RegQueryValueEx(hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength); long lngStatus = RegQueryValueEx(d->hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength);
if(lngStatus == ERROR_MORE_DATA){ if(lngStatus == ERROR_MORE_DATA){
lngStatus = RegQueryValueEx(hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength); lngStatus = RegQueryValueEx(d->hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength);
} }
int intReturn = (int)_atoi64(Buff); int intReturn = (int)_atoi64(Buff);
vReturn.push_back(intReturn); vReturn.push_back(intReturn);
@ -379,7 +388,7 @@ int* TelldusSettings::getArguments(int intDeviceId){
else{ else{
throw exception(); //couldn't open reg key throw exception(); //couldn't open reg key
} }
RegCloseKey(hk); RegCloseKey(d->hk);
intReturn = new int[vReturn.size()]; intReturn = new int[vReturn.size()];
@ -399,7 +408,7 @@ int* TelldusSettings::getArguments(int intDeviceId){
/* /*
* Set device arguments * Set device arguments
*/ */
bool TelldusSettings::setArguments(int intDeviceId, int* intArguments[], int intNumberOfArguments){ /* bool TelldusSettings::setArguments(int intDeviceId, int* intArguments[], int intNumberOfArguments){
bool blnSuccess = true; bool blnSuccess = true;
try{ try{
@ -427,12 +436,12 @@ bool TelldusSettings::setArguments(int intDeviceId, int* intArguments[], int int
blnSuccess = false; blnSuccess = false;
} }
return blnSuccess; return blnSuccess;
} }*/
/* /*
* Set device arguments * Set device arguments
*/ */
bool TelldusSettings::setArguments(int intDeviceId, vector <int> vArguments){ /* bool TelldusSettings::setArguments(int intDeviceId, vector <int> vArguments){
bool blnSuccess = true; bool blnSuccess = true;
try{ try{
@ -463,7 +472,7 @@ bool TelldusSettings::setArguments(int intDeviceId, vector <int> vArguments){
blnSuccess = false; blnSuccess = false;
} }
return blnSuccess; return blnSuccess;
} }*/
/* /*
@ -478,7 +487,7 @@ int TelldusSettings::addDevice(){
intDeviceId = getNextDeviceId(); intDeviceId = getNextDeviceId();
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
if(RegCreateKeyEx(HKEY_CURRENT_USER, if(RegCreateKeyEx(HKEY_CURRENT_USER,
@ -488,13 +497,13 @@ int TelldusSettings::addDevice(){
REG_OPTION_NON_VOLATILE, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
NULL, NULL,
&hk, &d->hk,
&dwDisp)){ &dwDisp)){
//fail //fail
throw exception("Create Key failed"); throw exception("Create Key failed");
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
@ -511,24 +520,24 @@ int TelldusSettings::getNextDeviceId(){
int intReturn = -1; int intReturn = -1;
try{ try{
DWORD dwDisp; DWORD dwDisp;
long lnExists = RegCreateKeyEx(HKEY_CURRENT_USER, strRegPathDevice.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, long lnExists = RegCreateKeyEx(HKEY_CURRENT_USER, d->strRegPathDevice.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
NULL, NULL,
&hk, &d->hk,
&dwDisp); //create or open if already created &dwDisp); //create or open if already created
if(lnExists == ERROR_SUCCESS){ if(lnExists == ERROR_SUCCESS){
DWORD dwLength; DWORD dwLength;
char* Buff = new char[intMaxRegValueLength]; char* Buff = new char[d->intMaxRegValueLength];
long lngStatus = RegQueryValueEx(hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength); long lngStatus = RegQueryValueEx(d->hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength);
if(lngStatus == ERROR_MORE_DATA){ if(lngStatus == ERROR_MORE_DATA){
Buff = new char[dwLength]; Buff = new char[dwLength];
lngStatus = RegQueryValueEx(hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength); lngStatus = RegQueryValueEx(d->hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength);
} }
if(lngStatus == ERROR_SUCCESS){ if(lngStatus == ERROR_SUCCESS){
@ -543,10 +552,10 @@ int TelldusSettings::getNextDeviceId(){
DWORD dwVal = intReturn; DWORD dwVal = intReturn;
RegSetValueEx (hk, "LastUsedId", 0L, REG_DWORD, (CONST BYTE*) &dwVal, sizeof(DWORD)); RegSetValueEx (d->hk, "LastUsedId", 0L, REG_DWORD, (CONST BYTE*) &dwVal, sizeof(DWORD));
} }
RegCloseKey(hk); RegCloseKey(d->hk);
} }
catch(...){ catch(...){
intReturn = -1; intReturn = -1;
@ -562,7 +571,7 @@ bool TelldusSettings::removeDevice(int intDeviceId){
bool blnSuccess = true; bool blnSuccess = true;
try{ try{
std::ostringstream ssRegPath; std::ostringstream ssRegPath;
ssRegPath << strRegPathDevice << intDeviceId; ssRegPath << d->strRegPathDevice << intDeviceId;
string strCompleteRegPath = ssRegPath.str(); string strCompleteRegPath = ssRegPath.str();
long lngSuccess = RegDeleteKey(HKEY_CURRENT_USER, strCompleteRegPath.c_str()); long lngSuccess = RegDeleteKey(HKEY_CURRENT_USER, strCompleteRegPath.c_str());