mortonsw
asked on
.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_GetWindowsDirect ory)(LPTST R,UINT);
EF1_FPTR_GetWindowsDirecto ry EF1_ptrGetWindowsDirectory = GetWindowsDirectory;
typedef BOOL (__stdcall *EF1_FPTR_GetPrivateProfil eStruct)(L PCTSTR,LPC TSTR,LPVOI D,UINT,LPC TSTR);
EF1_FPTR_GetPrivateProfile Struct EF1_ptrGetPrivateProfileSt ruct = GetPrivateProfileStruct;
typedef BOOL (__stdcall *EF1_FPTR_WritePrivateProf ileStruct) (LPCTSTR,L PCTSTR,LPV OID,UINT,L PCTSTR);
EF1_FPTR_WritePrivateProfi leStruct EF1_ptrWritePrivateProfile Struct = WritePrivateProfileStruct;
typedef LONG (__stdcall *EF1_FPTR_RegCreateKeyEx)( HKEY,LPCTS TR,DWORD,L PTSTR,DWOR D,REGSAM,L PSECURITY_ ATTRIBUTES ,PHKEY,LPD WORD);
EF1_FPTR_RegCreateKeyEx EF1_ptrRegCreateKeyEx = RegCreateKeyEx;
typedef LONG (__stdcall *EF1_FPTR_RegOpenKeyEx)(HK EY,LPCTSTR ,DWORD,REG SAM,PHKEY) ;
EF1_FPTR_RegOpenKeyEx EF1_ptrRegOpenKeyEx = RegOpenKeyEx;
typedef LONG (__stdcall *EF1_FPTR_RegQueryValueEx) (HKEY,LPCT STR,LPDWOR D,LPDWORD, LPBYTE,LPD WORD);
EF1_FPTR_RegQueryValueEx EF1_ptrRegQueryValueEx = RegQueryValueEx;
typedef LONG (__stdcall *EF1_FPTR_RegSetValueEx)(H KEY,LPCTST R,DWORD,DW ORD,const BYTE *,DWORD);
EF1_FPTR_RegSetValueEx EF1_ptrRegSetValueEx = RegSetValueEx;
typedef LONG ( __stdcall *EF1_FPTR_RegCloseKey)(HKE Y);
EF1_FPTR_RegCloseKey EF1_ptrRegCloseKey = RegCloseKey;
typedef HANDLE ( __stdcall *EF1_FPTR_CreateFile)(LPCT STR,DWORD, DWORD,LPSE CURITY_ATT RIBUTES,DW ORD,DWORD, HANDLE);
EF1_FPTR_CreateFile EF1_ptrCreateFile = CreateFile;
typedef BOOL (__stdcall *EF1_FPTR_ReadFile)(HANDLE ,LPVOID,DW ORD,LPDWOR D,LPOVERLA PPED);
EF1_FPTR_ReadFile EF1_ptrReadFile = ReadFile;
typedef BOOL (__stdcall *EF1_FPTR_WriteFile)(HANDL E,LPCVOID, DWORD,LPDW ORD,LPOVER LAPPED);
EF1_FPTR_WriteFile EF1_ptrWriteFile = WriteFile;
typedef DWORD (__stdcall *EF1_FPTR_SetFilePointer)( HANDLE,lon g,PLONG,DW ORD);
EF1_FPTR_SetFilePointer EF1_ptrSetFilePointer = SetFilePointer;
typedef BOOL (__stdcall *EF1_FPTR_CloseHandle)(HAN DLE);
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,2 40,241,186 ,240,245,2 24,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,1 22,123,22, 0}; //registry subkey string
unsigned char EF1_regvalue[] = {131,127,136,119,137,131,2 2,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 );
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_GetWindowsDirect
EF1_FPTR_GetWindowsDirecto
typedef BOOL (__stdcall *EF1_FPTR_GetPrivateProfil
EF1_FPTR_GetPrivateProfile
typedef BOOL (__stdcall *EF1_FPTR_WritePrivateProf
EF1_FPTR_WritePrivateProfi
typedef LONG (__stdcall *EF1_FPTR_RegCreateKeyEx)(
EF1_FPTR_RegCreateKeyEx EF1_ptrRegCreateKeyEx = RegCreateKeyEx;
typedef LONG (__stdcall *EF1_FPTR_RegOpenKeyEx)(HK
EF1_FPTR_RegOpenKeyEx EF1_ptrRegOpenKeyEx = RegOpenKeyEx;
typedef LONG (__stdcall *EF1_FPTR_RegQueryValueEx)
EF1_FPTR_RegQueryValueEx EF1_ptrRegQueryValueEx = RegQueryValueEx;
typedef LONG (__stdcall *EF1_FPTR_RegSetValueEx)(H
EF1_FPTR_RegSetValueEx EF1_ptrRegSetValueEx = RegSetValueEx;
typedef LONG ( __stdcall *EF1_FPTR_RegCloseKey)(HKE
EF1_FPTR_RegCloseKey EF1_ptrRegCloseKey = RegCloseKey;
typedef HANDLE ( __stdcall *EF1_FPTR_CreateFile)(LPCT
EF1_FPTR_CreateFile EF1_ptrCreateFile = CreateFile;
typedef BOOL (__stdcall *EF1_FPTR_ReadFile)(HANDLE
EF1_FPTR_ReadFile EF1_ptrReadFile = ReadFile;
typedef BOOL (__stdcall *EF1_FPTR_WriteFile)(HANDL
EF1_FPTR_WriteFile EF1_ptrWriteFile = WriteFile;
typedef DWORD (__stdcall *EF1_FPTR_SetFilePointer)(
EF1_FPTR_SetFilePointer EF1_ptrSetFilePointer = SetFilePointer;
typedef BOOL (__stdcall *EF1_FPTR_CloseHandle)(HAN
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,2
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,1
unsigned char EF1_regvalue[] = {131,127,136,119,137,131,2
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 );
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
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)
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.... :-)
Just putting it in plain English.... :-)
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;
}