PDA

View Full Version : Strange error project compiling



SIFE
27th December 2011, 02:56
I have this class:

#include <iostream>

#include "register.h"

using namespace std;

int Register::GetMacAddress(char *mac)
{
NCB ncb;
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
} ASTAT, * PASTAT;
ASTAT Adapter;
//ADAPTER_STATUS Adapter;
LANA_ENUM lana_enum;
UCHAR uRetCode;
memset( &ncb, 0, sizeof(ncb) );
memset( &lana_enum, 0, sizeof(lana_enum));

ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *) &lana_enum;
ncb.ncb_length = sizeof(LANA_ENUM);
uRetCode = Netbios( &ncb );
if( uRetCode != NRC_GOODRET )
return uRetCode ;

for( int lana=0; lana<lana_enum.length; lana++ )
{
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_enum.lana[lana];
uRetCode = Netbios( &ncb );
if( uRetCode == NRC_GOODRET )
break ;
}
if( uRetCode != NRC_GOODRET )
return uRetCode;

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_enum.lana[0];
strcpy( (char* )ncb.ncb_callname, "*" );
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios( &ncb );
if( uRetCode != NRC_GOODRET )
return uRetCode ;
sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
return 0;
}

void Register::CopyRight()
{
cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl;
cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl;
cerr<<"2000.11.3"<<endl<<endl;
}

VOID Register::ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
{
USHORT i;
CHAR temp;

for (i = 0; i < uscStrSize; i+=2)
{
temp = szString[i];
szString[i] = szString[i+1];
szString[i+1] = temp;
}
}

void Register::hdidnt(char *s)
{
char hd[80];
PIDSECTOR phdinfo;

ZeroMemory(&vers,sizeof(vers));
//We start in NT/Win2000
for (j=0;j<4;++j){
sprintf(hd,"\\\\.\\PhysicalDrive%d",j);
h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0 ,0);
if (!h){
continue;
}
if (!DeviceIoControl(h, DFP_GET_VERSION, 0, 0, &vers, sizeof(vers), &i, 0)){
CloseHandle(h);
continue;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Identify the IDE drives
ZeroMemory(&in, sizeof(in));
ZeroMemory(&out, sizeof(out));
if (j & 1){
in.irDriveRegs.bDriveHeadReg = 0xb0;
}else{
in.irDriveRegs.bDriveHeadReg = 0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;

continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout << "\tSerial Number:" << s <<endl;
CloseHandle(h);
}
CopyRight();
}
Register.h:

#ifndef REGISTER_H
#define REGISTER_H

#include <windows.h>
#include "GetDisk.h"

class Register
{
public:
void ChangeByteOrder(PCHAR szString, USHORT uscStrSize);
int GetMacAddress(char *mac);
void CopyRight();
void hdidnt(char *s);

private:
GETVERSIONOUTPARAMS vers;
SENDCMDINPARAMS in;
SENDCMDOUTPARAMS out;
HANDLE h;
DWORD i;
BYTE j;
};

#endif
With this simple test application, compilation work fine:

#include <iostream>

#include "register.h"

using namespace std;

int main(int argc, char *argv[])
{
char mac[20];
char s[20];
Register reg;
reg.GetMacAddress(mac);
cout << mac << endl;
reg.hdidnt(s);
return 0;
}
Now if I embedded this class in Qt project I see this error:
.
.\KtanR\register.cpp: In member function 'void Register::hdidnt(char*)':

..\KtanR\register.cpp:98: error: cannot convert 'char*' to 'const WCHAR*' for argument '1' to 'void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'

mingw32-make.exe[1]: *** [release/register.o] Error 1

mingw32-make.exe: *** [release] Error 2

The process "C:/MinGW/bin/mingw32-make.exe" exited with code %2.
Error while building project Store (target: Desktop)
When executing build step 'Make'
Both example and Qt project compiled with some compiler. Any suggestion?

amleto
27th December 2011, 12:43
firstly, ugh - why are you using so much unsafe c code?

secondly, if you only care about windows, why are you making your own byte order method instead of using ntol?

thirdly, where is your qt code?

fourthly, if this really IS qt code, why not use qfile etc to make a file instead of windows api?

fifthly, I think your error is mismatch of ansi/unicode settings.

SIFE
30th December 2011, 00:03
firstly, ugh - why are you using so much unsafe c code?

secondly, if you only care about windows, why are you making your own byte order method instead of using ntol?
I just copied the functions because my project need it, and I have no time to write theme from scratch.

thirdly, where is your qt code?
I am asking just for error compilation.

fourthly, if this really IS qt code, why not use qfile etc to make a file instead of windows api?
Because this a platform specific. The author of code trying to query device(hard disk in my case, to get serial number).

fifthly, I think your error is mismatch of ansi/unicode settings.
Looks like that, I changed CreateFileW to CreateFileA, then the error gone. Seems like CreateFileW (unicode version) doesn't work well with Qt 4.7.4.

Spitfire
4th January 2012, 14:52
It has nothing to do with Qt.

You're trying to pass a char* pointer to a function that expects wchar*.

The error tells you everything.

SIFE
4th January 2012, 22:08
You're trying to pass a char* pointer to a function that expects wchar*.
Now thinks come more clear.