Solved

.c typedefs error when .cpp?

Posted on 2002-06-13
4
1,405 Views
Last Modified: 2008-03-10
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
Comment
Question by:mortonsw
  • 3
4 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 100 total points
ID: 7075044
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
 
LVL 30

Expert Comment

by:Axter
ID: 7075057
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
 
LVL 30

Expert Comment

by:Axter
ID: 7075089
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
 
LVL 4

Expert Comment

by:mblat
ID: 7075886
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now