Just decided to try the new Code::Blocks IDE on an old ODBC program of mine that I had always compiled as a C program. I decided to redo it as a C++ program and immediately hit a nasty problem that I never ran into in C. It involves a Typedef of char from char* to SQLCHAR*. The below example very concisely shows the problem. I can use strcpy to copy a literal char array to a char*, but not to a SQLCHAR*. This has worked flawlessly for me for years in C. No errors, no warnings, runs perfectly, etc. I was so amazed I tried it with Dev C++ but with the same result. Can anyone tell me what's wrong or how to fix it?
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "odbcinst.h"
#include "sql.h" //ODBC header file
#include "sqlext.h" //ODBC header file
int main()
{
char szBuffer[64];
SQLCHAR szString[64];
strcpy(szBuffer,"Any Old String");
printf("szBuffer = %s\n",szBuffer);
strcpy(szString,"Let's Try This!");
return 0;
}
/*
COMPILER OUTPUT
Main.cpp: In function `int main()':
Main.cpp:15: error: invalid conversion from `SQLCHAR*' to `char*'
Main.cpp:15: error: initializing argument 1 of `char* strcpy(char*, const char*)'
make.exe: *** [Main.o] Error 1
Execution terminated
*/