Solved

.c typedefs error when .cpp?

Posted on 2002-06-13
4
1,403 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 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

20 Experts available now in Live!

Get 1:1 Help Now