[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1501
  • Last Modified:

.c typedefs error when .cpp?

I get errors after changing extension from .c to .cpp but I don't understand what's wrong:

comdlg32.cpp(155) : error C2664: 'strcat' : cannot convert parameter 2 from 'unsigned char [13]' to 'const char *' (new behavior; please see help)
comdlg32.cpp(167) : error C2664: 'int (__stdcall *)(void *,void *,unsigned long,unsigned long *,struct _OVERLAPPED *)' : cannot convert parameter 2 from 'int *' to 'unsigned long *' (new behavior; please see help)
comdlg32.cpp(189) : error C2664: 'int (__stdcall *)(void *,const void *,unsigned long,unsigned long *,struct _OVERLAPPED *)' : cannot convert parameter 2 from 'int *' to 'unsigned long *' (new behavior; please see help)

comdlg32.cpp(162) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long,unsigned long,void ** )' : cannot convert parameter 4 from 'unsigned char [9]' to 'const char *' (new behavior; please see help)
comdlg32.cpp(164) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)' : cannot convert parameter 5 from 'unsigned char [7]' to 'const char *' (new behavior; please see help)
comdlg32.cpp(164) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)' : cannot convert parameter 2 from 'char *' to 'unsigned char *' (new behavior; please see help)
comdlg32.cpp(164) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)' : cannot convert parameter 1 from 'int *' to 'unsigned long *' (new behavior; please see help)
comdlg32.cpp(186) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long,char *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES *,void ** ,unsigned long *)' : cannot convert parameter 8 from 'unsigned char [9]' to 'const char *' (new behavior; please see help)
comdlg32.cpp(186) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long,char *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES *,void ** ,unsigned long *)' : cannot convert parameter 1 from 'int *' to 'unsigned long *' (new behavior; please see help)
comdlg32.cpp(187) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long,unsigned long,const unsigned char *,unsigned long)' : cannot convert parameter 5 from 'unsigned char [7]' to 'const char *' (new behavior; please see help)
comdlg32.cpp(187) : error C2664: 'long (__stdcall *)(void *,const char *,unsigned long,unsigned long,const unsigned char *,unsigned long)' : cannot convert parameter 2 from 'char *' to 'const unsigned char *' (new behavior; please see help)

comdlg32.cpp:

  typedef UINT (__stdcall *EF1_FPTR_GetWindowsDirectory)(LPTSTR,UINT);
  EF1_FPTR_GetWindowsDirectory EF1_ptrGetWindowsDirectory = GetWindowsDirectory;

  typedef BOOL (__stdcall *EF1_FPTR_GetPrivateProfileStruct)(LPCTSTR,LPCTSTR,LPVOID,UINT,LPCTSTR);
  EF1_FPTR_GetPrivateProfileStruct EF1_ptrGetPrivateProfileStruct = GetPrivateProfileStruct;

  typedef BOOL (__stdcall *EF1_FPTR_WritePrivateProfileStruct)(LPCTSTR,LPCTSTR,LPVOID,UINT,LPCTSTR);
  EF1_FPTR_WritePrivateProfileStruct EF1_ptrWritePrivateProfileStruct = WritePrivateProfileStruct;

  typedef LONG (__stdcall *EF1_FPTR_RegCreateKeyEx)(HKEY,LPCTSTR,DWORD,LPTSTR,DWORD,REGSAM,LPSECURITY_ATTRIBUTES,PHKEY,LPDWORD);
  EF1_FPTR_RegCreateKeyEx EF1_ptrRegCreateKeyEx = RegCreateKeyEx;

  typedef LONG (__stdcall *EF1_FPTR_RegOpenKeyEx)(HKEY,LPCTSTR,DWORD,REGSAM,PHKEY);
  EF1_FPTR_RegOpenKeyEx EF1_ptrRegOpenKeyEx = RegOpenKeyEx;

  typedef LONG (__stdcall *EF1_FPTR_RegQueryValueEx)(HKEY,LPCTSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
  EF1_FPTR_RegQueryValueEx EF1_ptrRegQueryValueEx = RegQueryValueEx;

  typedef LONG (__stdcall *EF1_FPTR_RegSetValueEx)(HKEY,LPCTSTR,DWORD,DWORD,const BYTE *,DWORD);
  EF1_FPTR_RegSetValueEx EF1_ptrRegSetValueEx = RegSetValueEx;

  typedef LONG ( __stdcall *EF1_FPTR_RegCloseKey)(HKEY);
  EF1_FPTR_RegCloseKey EF1_ptrRegCloseKey = RegCloseKey;

  typedef HANDLE ( __stdcall *EF1_FPTR_CreateFile)(LPCTSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE);
  EF1_FPTR_CreateFile EF1_ptrCreateFile = CreateFile;

  typedef BOOL (__stdcall *EF1_FPTR_ReadFile)(HANDLE,LPVOID,DWORD,LPDWORD,LPOVERLAPPED);
  EF1_FPTR_ReadFile EF1_ptrReadFile = ReadFile;

  typedef BOOL (__stdcall *EF1_FPTR_WriteFile)(HANDLE,LPCVOID,DWORD,LPDWORD,LPOVERLAPPED);
  EF1_FPTR_WriteFile EF1_ptrWriteFile = WriteFile;

  typedef DWORD (__stdcall *EF1_FPTR_SetFilePointer)(HANDLE,long,PLONG,DWORD);
  EF1_FPTR_SetFilePointer EF1_ptrSetFilePointer = SetFilePointer;

  typedef BOOL (__stdcall *EF1_FPTR_CloseHandle)(HANDLE);
  EF1_FPTR_CloseHandle EF1_ptrCloseHandle = CloseHandle;

  EF1_S_EXPDATA     EF1_expdata;                                  //expiration data
  int               EF1_bytesio;                                  //total bytes read or written
  int               EF1_r;                                        //value returned to us

  unsigned char     EF1_filename[] = {249,253,230,245,247,251,240,241,186,240,245,224,148,0};      //file name
  char              EF1_filespec[MAX_PATH];                       //file spec
  HANDLE            EF1_filehandle;                               //file handle

  HKEY              EF1_reghkey   = HKEY_LOCAL_MACHINE;           //registry hkey
  unsigned char     EF1_regsubkey[] = {131,127,136,119,121,133,122,123,22,0};    //registry subkey string
  unsigned char     EF1_regvalue[]  = {131,127,136,119,137,131,22,0};     //registry value name
  HKEY              EF1_reghandle;                                //registry key handle
  int               EF1_regstatus;                                //registry operation status

155:    strcat ( EF1_filespec , EF1_filename );
162:    EF1_r = EF1_ptrRegOpenKeyEx ( EF1_reghkey , EF1_regsubkey , 0 , KEY_QUERY_VALUE , &EF1_reghandle );
164:    EF1_r = EF1_ptrRegQueryValueEx ( EF1_reghandle , EF1_regvalue , NULL , NULL , (char *)&EF1_expdata , &EF1_bytesio );
167:    EF1_r = EF1_ptrReadFile ( EF1_filehandle , &EF1_expdata , sizeof(EF1_expdata) , &EF1_bytesio , NULL );
186:    EF1_r = EF1_ptrRegCreateKeyEx ( EF1_reghkey , EF1_regsubkey , 0 , NULL , REG_OPTION_NON_VOLATILE , KEY_WRITE , NULL , &EF1_reghandle , &EF1_regstatus );
187:    EF1_r = EF1_ptrRegSetValueEx ( EF1_reghandle , EF1_regvalue , 0 , REG_BINARY , (char *)&EF1_expdata , sizeof (EF1_expdata) );
189:    EF1_r = EF1_ptrWriteFile ( EF1_filehandle , &EF1_expdata , sizeof(EF1_expdata) , &EF1_bytesio , NULL );
0
mortonsw
Asked:
mortonsw
  • 3
1 Solution
 
AxterCommented:
In C++, you can't mix char and unsigned char without casting.
For example, if you want to use the function strcat with an unsigned char, you need to do the following:
strcat((char*)EF1_filespec , (const char*)EF1_filename );
0
 
AxterCommented:
The VC++ compiler allows for mixing signed and unsigned char with *.c files, but it doesn't allow it for *.cpp (C++) files.

For example, the following code will compile as a *.c file, but it will not compile as a *.cpp file:

#include <string.h>

int main(int argc, char* argv[])
{
     unsigned char * Data = "Hello World";
     unsigned char Dest[64] = "";
     char * Data2 = "Hello World";
     char Dest2[64] = "";
     strcpy(Dest, Data);
     strcpy(Dest2, Data2);
     return 0;
}
0
 
AxterCommented:
Correction:
In C++, you can't mix signed char and unsigned char without casting.


If in your code you plan to use all signed char for your char type, you can use the following compiler option:
/J   (Default char Type is unsigned)
0
 
mblatCommented:
Basically, what Axter is saying here. C++ has more stringent type chacking than C.  What can fly in C, can't in C++.  
 Just putting it in plain English.... :-)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now