Solved

.c typedefs error when .cpp?

Posted on 2002-06-13
4
1,449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

623 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