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;


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

Recommended Answers

All 2 Replies

As far as I know, SQLCHAR is a typedef for unsigned char* (or signed char* in other versions). If so, use brutal force method (in C style):

strcpy((char*)szString,"Let's Try This!");
commented: helped me a lot. i was stuck +1

Thanks ArkM. That did it! The 'Brutal Force Method' suits my coding style anyhow!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.