Results 1 to 5 of 5

Thread: Strange error project compiling

  1. #1
    Join Date
    Feb 2011
    Posts
    64
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 2 Posts

    Default Strange error project compiling

    I have this class:
    Qt Code:
    1. #include <iostream>
    2.  
    3. #include "register.h"
    4.  
    5. using namespace std;
    6.  
    7. int Register::GetMacAddress(char *mac)
    8. {
    9. NCB ncb;
    10. typedef struct _ASTAT_
    11. {
    12. ADAPTER_STATUS adapt;
    13. NAME_BUFFER NameBuff [30];
    14. } ASTAT, * PASTAT;
    15. ASTAT Adapter;
    16. //ADAPTER_STATUS Adapter;
    17. LANA_ENUM lana_enum;
    18. UCHAR uRetCode;
    19. memset( &ncb, 0, sizeof(ncb) );
    20. memset( &lana_enum, 0, sizeof(lana_enum));
    21.  
    22. ncb.ncb_command = NCBENUM;
    23. ncb.ncb_buffer = (unsigned char *) &lana_enum;
    24. ncb.ncb_length = sizeof(LANA_ENUM);
    25. uRetCode = Netbios( &ncb );
    26. if( uRetCode != NRC_GOODRET )
    27. return uRetCode ;
    28.  
    29. for( int lana=0; lana<lana_enum.length; lana++ )
    30. {
    31. ncb.ncb_command = NCBRESET;
    32. ncb.ncb_lana_num = lana_enum.lana[lana];
    33. uRetCode = Netbios( &ncb );
    34. if( uRetCode == NRC_GOODRET )
    35. break ;
    36. }
    37. if( uRetCode != NRC_GOODRET )
    38. return uRetCode;
    39.  
    40. memset( &ncb, 0, sizeof(ncb) );
    41. ncb.ncb_command = NCBASTAT;
    42. ncb.ncb_lana_num = lana_enum.lana[0];
    43. strcpy( (char* )ncb.ncb_callname, "*" );
    44. ncb.ncb_buffer = (unsigned char *) &Adapter;
    45. ncb.ncb_length = sizeof(Adapter);
    46. uRetCode = Netbios( &ncb );
    47. if( uRetCode != NRC_GOODRET )
    48. return uRetCode ;
    49. sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",
    50. Adapter.adapt.adapter_address[0],
    51. Adapter.adapt.adapter_address[1],
    52. Adapter.adapt.adapter_address[2],
    53. Adapter.adapt.adapter_address[3],
    54. Adapter.adapt.adapter_address[4],
    55. Adapter.adapt.adapter_address[5] );
    56. return 0;
    57. }
    58.  
    59. void Register::CopyRight()
    60. {
    61. cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl;
    62. cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl;
    63. cerr<<"2000.11.3"<<endl<<endl;
    64. }
    65.  
    66. VOID Register::ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
    67. {
    68. USHORT i;
    69. CHAR temp;
    70.  
    71. for (i = 0; i < uscStrSize; i+=2)
    72. {
    73. temp = szString[i];
    74. szString[i] = szString[i+1];
    75. szString[i+1] = temp;
    76. }
    77. }
    78.  
    79. void Register::hdidnt(char *s)
    80. {
    81. char hd[80];
    82. PIDSECTOR phdinfo;
    83.  
    84. ZeroMemory(&vers,sizeof(vers));
    85. //We start in NT/Win2000
    86. for (j=0;j<4;++j){
    87. sprintf(hd,"\\\\.\\PhysicalDrive%d",j);
    88. h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE,
    89. FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
    90. if (!h){
    91. continue;
    92. }
    93. if (!DeviceIoControl(h, DFP_GET_VERSION, 0, 0, &vers, sizeof(vers), &i, 0)){
    94. CloseHandle(h);
    95. continue;
    96. }
    97. //If IDE identify command not supported, fails
    98. if (!(vers.fCapabilities&1)){
    99. cout<<"Error: IDE identify command not supported.";
    100. CloseHandle(h);
    101. return;
    102. }
    103. //Identify the IDE drives
    104. ZeroMemory(&in, sizeof(in));
    105. ZeroMemory(&out, sizeof(out));
    106. if (j & 1){
    107. in.irDriveRegs.bDriveHeadReg = 0xb0;
    108. }else{
    109. in.irDriveRegs.bDriveHeadReg = 0xa0;
    110. }
    111. if (vers.fCapabilities&(16>>j)){
    112. //We don't detect a ATAPI device.
    113. cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
    114.  
    115. continue;
    116. }else{
    117. in.irDriveRegs.bCommandReg=0xec;
    118. }
    119. in.bDriveNumber=j;
    120. in.irDriveRegs.bSectorCountReg=1;
    121. in.irDriveRegs.bSectorNumberReg=1;
    122. in.cBufferSize=512;
    123. if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
    124. cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
    125. CloseHandle(h);
    126. return;
    127. }
    128. phdinfo=(PIDSECTOR)out.bBuffer;
    129. memcpy(s,phdinfo->sSerialNumber,20);
    130. s[20]=0;
    131. ChangeByteOrder(s,20);
    132. cout << "\tSerial Number:" << s <<endl;
    133. CloseHandle(h);
    134. }
    135. CopyRight();
    136. }
    To copy to clipboard, switch view to plain text mode 
    Register.h:
    Qt Code:
    1. #ifndef REGISTER_H
    2. #define REGISTER_H
    3.  
    4. #include <windows.h>
    5. #include "GetDisk.h"
    6.  
    7. class Register
    8. {
    9. public:
    10. void ChangeByteOrder(PCHAR szString, USHORT uscStrSize);
    11. int GetMacAddress(char *mac);
    12. void CopyRight();
    13. void hdidnt(char *s);
    14.  
    15. private:
    16. GETVERSIONOUTPARAMS vers;
    17. SENDCMDINPARAMS in;
    18. SENDCMDOUTPARAMS out;
    19. HANDLE h;
    20. DWORD i;
    21. BYTE j;
    22. };
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 
    With this simple test application, compilation work fine:
    Qt Code:
    1. #include <iostream>
    2.  
    3. #include "register.h"
    4.  
    5. using namespace std;
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. char mac[20];
    10. char s[20];
    11. Register reg;
    12. reg.GetMacAddress(mac);
    13. cout << mac << endl;
    14. reg.hdidnt(s);
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 
    Now if I embedded this class in Qt project I see this error:
    .
    Qt Code:
    1. .\KtanR\register.cpp: In member function 'void Register::hdidnt(char*)':
    2.  
    3. ..\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*)'
    4.  
    5. mingw32-make.exe[1]: *** [release/register.o] Error 1
    6.  
    7. mingw32-make.exe: *** [release] Error 2
    8.  
    9. The process "C:/MinGW/bin/mingw32-make.exe" exited with code %2.
    10. Error while building project Store (target: Desktop)
    11. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 
    Both example and Qt project compiled with some compiler. Any suggestion?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Strange error project compiling

    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.
    Last edited by amleto; 27th December 2011 at 12:51.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. The following user says thank you to amleto for this useful post:

    SIFE (4th January 2012)

  4. #3
    Join Date
    Feb 2011
    Posts
    64
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 2 Posts

    Default Re: Strange error project compiling

    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.
    Qt Code:
    1. fourthly, if this really IS qt code, why not use qfile etc to make a file instead of windows api?
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: Strange error project compiling

    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.

  6. The following user says thank you to Spitfire for this useful post:

    SIFE (4th January 2012)

  7. #5
    Join Date
    Feb 2011
    Posts
    64
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 2 Times in 2 Posts

    Default Re: Strange error project compiling

    You're trying to pass a char* pointer to a function that expects wchar*.
    Now thinks come more clear.

Similar Threads

  1. Replies: 0
    Last Post: 20th November 2011, 13:41
  2. Replies: 2
    Last Post: 15th February 2010, 07:42
  3. Error while compiling a new basic project
    By sudheer168 in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2009, 09:25
  4. Error while compiling a new basic project
    By sudheer168 in forum Installation and Deployment
    Replies: 0
    Last Post: 17th August 2009, 08:34
  5. Extra qualification error while compiling the project file
    By amit_pansuria in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2007, 08:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.