Solved

.c typedefs error when .cpp?

Posted on 2002-06-13
4
1,430 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Dialogbox API leak? 18 120
Microsoft C++ code failing in executable that worked 9 146
Safe conversion? 4 88
How do i run a c++ file? 15 58
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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

710 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