How do I fix these errors and why am I getting them?

And a few others assorted questions.

I'm trying to implement connecting to Access via C++. Using Codeblocks as my IDE.

I got the source code from this site : http://www.powerbasic.com/support/pbforums/showthread.php?t=24912&highlight=Using+ODBC+Direct

[code#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "odbcinst.h"
#include "sql.h" //ODBC header file
#include "sqlext.h" //ODBC header file
//
typedef struct tagSQL //This type helps with some 'grungy' initialization work
{ //in setting up an ODBC environment
SQLCHAR szCnIn[512];
SQLCHAR szCnOut[512];
short int iBytes;
SWORD swStrLen;
SQLHENV hEnvr;
SQLHDBC hConn;
unsigned int blnConnected;
}SQL,*lpSql;
//
typedef struct tagDiagRec //ODBC functions return wonderful error information
{ //and this type helps in setting it up. I have
SQLINTEGER iNativeErrPtr; //found this the best way to do it, and
SQLSMALLINT iTextLenPtr; //believe me, you need this error info!
SQLCHAR szErrMsg[512];
SQLCHAR szErrCode[8];
}DIAGNOSTICRECORD;
//
//
void ODBCConnect(SQLCHAR *szDB,lpSql sql) //Fairly ugly stuff in here and you want to try
{ //to keep your application as isolated from it
DIAGNOSTICRECORD dr; //as possible. After you have the connection
char lpBuffer[512]; //set up all you need is one function to get
DWORD nBufLen=512; //a statement handle, 'SQLAllocHandle()' to use
UINT iResult; //SQL statements to Select, Update, and Insert data
//
SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&sql->hEnvr);
SQLSetEnvAttr(sql->hEnvr,SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3,SQL_IS_INTEGER);
SQLAllocHandle(SQL_HANDLE_DBC,sql->hEnvr,&sql->hConn); //returns handle to connection
strcpy(sql->szCnIn,"DRIVER=Microsoft Access Driver (*.mdb);DBQ="); //move string to buffer
GetCurrentDirectory(nBufLen,lpBuffer);
printf("lpBuffer=%s\n",lpBuffer);
strcat(sql->szCnIn,lpBuffer);
strcat(sql->szCnIn,"\\");
strcat(sql->szCnIn,szDB);
strcat(sql->szCnIn,";");
printf("sql->szCnIn = %s\n",sql->szCnIn);
iResult=
SQLDriverConnect //this is the big connection function
(
sql->hConn, //we just obtained sql->hConn above in last SQLAllocHandle() call
NULL, //handle to a window is optional
sql->szCnIn, //here is the connection string we just built
(SQLSMALLINT)strlen(sql->szCnIn), //here it wants the length of the connection string
sql->szCnOut, //if the function succeeds it will return to us the Conn str it used
512, //this is the length of the output buffer for the Conn str
&sql->swStrLen, //this is the number of bytes it actually returned
SQL_DRIVER_NOPROMPT //I'm telling it to fail rather than prompt me for more Conn info
);
if(!iResult)
sql->blnConnected=TRUE; //return TRUE if connection attempt was successful
else
{
SQLGetDiagRec //if the connection attempt fails we'll call this function
( //to obtain an explanation for the failure
SQL_HANDLE_DBC,
sql->hConn,
1,
dr.szErrCode,
&dr.iNativeErrPtr,
dr.szErrMsg,
512,
&dr.iTextLenPtr
);
printf("dr.szErrCode = %s\n",dr.szErrCode);
printf("dr.szErrMsg = %s\n",dr.szErrMsg);
sql->blnConnected=FALSE; //return FALSE if connection fails
SQLDisconnect(sql->hConn);
SQLFreeHandle(SQL_HANDLE_DBC ,sql->hConn);
SQLFreeHandle(SQL_HANDLE_ENV,sql->hEnvr);
}
}
//
//
void ODBCDisconnect(lpSql sql) //Disconnect from data source, and
{ //release connection and environment
SQLDisconnect(sql->hConn); //handles
SQLFreeHandle(SQL_HANDLE_DBC,sql->hConn);
SQLFreeHandle(SQL_HANDLE_ENV,sql->hEnvr);
}
//
//
void InstallerError(void)
{
DWORD pErr;
SQLCHAR szErrMsg[512];
WORD cbMsgBuffer=512;
WORD cbRet;
WORD wErrNum=1;
//
while(SQLInstallerError(wErrNum,&pErr,szErrMsg,cbMsgBuffer,&cbRet)!=SQL_NO_DATA)
{
printf("%u\t%u\t%s\n",wErrNum,pErr,szErrMsg);
wErrNum++;
};
//
return;
}
//
//
UINT blnCreateDB(SQLCHAR *szDBName) //Uses SQLConfigDataSource() to create Jet database
{
SQLCHAR szCreate[24];
//
printf("szDBName=%s\n",szDBName);
strcpy(szCreate,"CREATE_DB=");
strcat(szCreate,szDBName);
printf("szCreate=%s\n",szCreate);
if(SQLConfigDataSource(0,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)",szCreate))
{
printf("SQLConfigDataSource() returned TRUE\n");
return TRUE;
}
else
{
InstallerError();
return FALSE;
}
}
//
//
UINT blnMakeTable(lpSql sql) //Uses SQL Create Table statement to add table
{ //to database represented by sql->hConn
SQLCHAR szQuery[256];
SQLHSTMT hStmt;
//
strcpy(
szQuery,
"CREATE TABLE Table1 " \
"(" \
"Id LONG NOT NULL PRIMARY KEY," \
"Float_Point DOUBLE," \
"Date_Field DATETIME," \
"Text_Field CHAR(30)" \
");");
printf("%s\n",szQuery);
SQLAllocHandle(SQL_HANDLE_STMT,sql->hConn,&hStmt);
if(SQLExecDirect(hStmt,szQuery,SQL_NTS)==0)
{
puts("Table1 Successfully Created!");
SQLFreeHandle(SQL_HANDLE_STMT,hStmt);
return(TRUE);
}
else
{
puts("Table Creation Failure!"); //Here would be a good place to use
return(FALSE); //SQLGetDiagRec() if table creation fails
}
}
//
//
TIMESTAMP_STRUCT ParseDate(SQLCHAR *szDate,SQLCHAR *szFormat,SQLCHAR *szDelimiter)
{
UINT i=0,j=0,k=0; //PowerBASIC doesn't allow for the return of Types
TIMESTAMP_STRUCT ts; //but C does. Not really a big deal, in my mind.
SQLCHAR buf[3][8]; //buf[0] for month, buf[1] for day, buf[2] for year
SQLCHAR *p;
//
memset(buf,0,sizeof(buf)); //zero out buf[]
p=szDate; //set p equal to address of date string passed.
for(i=0;i<strlen(szDate);i++)
{
if(*p!=*szDelimiter) //move through date string stripping
{ //out numbers seperated by delimiters
buf[j][k++]=*p;
buf[j][k+1]='\0';
}
else
{
j++;
k=0;
}
p++;
}
if(!strcmpi(szFormat,"MDY")) //figure out what is suppossed to be
{ //in each buffer
ts.month=atoi(buf[0]);
ts.day=atoi(buf[1]);
ts.year=atoi(buf[2]);
}
if(!strcmpi(szFormat,"DMY"))
{
ts.day=atoi(buf[0]);
ts.month=atoi(buf[1]);
ts.year=atoi(buf[2]);
}
if(!strcmpi(szFormat,"YMD"))
{
ts.year=atoi(buf[0]);
ts.month=atoi(buf[1]);
ts.day=atoi(buf[2]);
}

return ts;
}
[/code]

To be continued....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
UINT blnInsert(lpSql sql)
{
 TIMESTAMP_STRUCT ts;
 DIAGNOSTICRECORD dr;
 SQLHSTMT         hStmt;
 SQLINTEGER       iJnk;
 SQLINTEGER       iNts=SQL_NTS;
 UINT             iId[]={1,2,3,4};
 double           dblNum[]={3.14159,1.23456,15.1234,0.54321};
 SQLCHAR          *szDate[]={"11/15/1952","6/30/1969","1/1/2006","4/1/2006"};
 SQLCHAR          *szStr[]={"My Birthday","Walk On Moon?","Some String","April Fools Day"};
 SQLCHAR          szQuery[100],szString[30];
 UINT             i,id,iRet=FALSE;
 double           dbl;
 //
 if(SQLAllocHandle(SQL_HANDLE_STMT,sql->hConn,&hStmt)==SQL_SUCCESS)
 {
    strcpy(
    szQuery,
    "INSERT INTO Table1 " \
    "(" \
      "Id," \
      "Float_Point," \
      "Date_Field," \
      "Text_Field" \
    ") " \
    "VALUES(?,?,?,?);");
    printf("%s\n",szQuery);
    if(SQLPrepare(hStmt,szQuery,SQL_NTS)==SQL_SUCCESS)
    {
       SQLBindParameter(hStmt,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&id,0,&iJnk);
       SQLBindParameter(hStmt,2,SQL_PARAM_INPUT,SQL_C_DOUBLE,SQL_DOUBLE,0,0,&dbl,0,&iJnk);
       SQLBindParameter(hStmt,3,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_DATE,0,0,&ts,0,&iJnk);
       SQLBindParameter(hStmt,4,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,29,0,szString,30,&iNts);
       printf("\n                                                         SQLExecute(hStmt)\n");
       printf("iId      Double           Date           String           0=SQL_SUCCESS  \n");
       printf("========================================================================\n");
       for(i=0;i<sizeof(iId)/sizeof(iId[0]);i++)
       {
           id=iId[i];dbl=dblNum[i];
           ts=ParseDate(szDate[i],"mdy","/");
           strcpy(szString,szStr[i]);
           if(SQLExecute(hStmt)==SQL_SUCCESS)
              printf("%u\t%f\t%s\t%s\t\t%u\n",id,dbl,szDate[i],szString,SQL_SUCCESS);
           else
           {
              SQLGetDiagRec
              (
                SQL_HANDLE_DBC,
                sql->hConn,
                1,
                dr.szErrCode,
                &dr.iNativeErrPtr,
                dr.szErrMsg,
                512,
                &dr.iTextLenPtr
              );
              printf("dr.szErrCode = %s\n",dr.szErrCode);
              printf("dr.szErrMsg  = %s\n",dr.szErrMsg);
              SQLFreeHandle(SQL_HANDLE_STMT,hStmt);
              return FALSE;
           }
       }
       iRet=TRUE;
       printf("\n");
    }
    SQLFreeHandle(SQL_HANDLE_STMT,hStmt);
 }
 //
 return iRet;
}
//
//
SQLCHAR *MkDate(TIMESTAMP_STRUCT *ts)
{
 SQLCHAR szMonth[4],szDay[4],szYear[8];
 static  SQLCHAR szDate[12];
 //
 sprintf(szMonth,"%u",ts->month);
 sprintf(szDay,"%u",ts->day);
 sprintf(szYear,"%u",ts->year);
 strcpy(szDate,szMonth);
 strcat(szDate,"/");
 strcat(szDate,szDay);
 strcat(szDate,"/");
 strcat(szDate,szYear);
 //
 return szDate;
}
//
//
UINT blnDumpData(lpSql sql)
{
 SQLHSTMT          hStmt;
 SQLCHAR           szQuery[100];
 SQLINTEGER        iJnk;
 UINT              iId;
 double            dblNum;
 TIMESTAMP_STRUCT  ts;
 SQLCHAR           szString[30];
 //
 if(SQLAllocHandle(SQL_HANDLE_STMT,sql->hConn,&hStmt)==SQL_SUCCESS)
 {
    strcpy(
    szQuery,
    "SELECT " \
      "Table1.Id," \
      "Table1.Float_Point," \
      "Table1.Date_Field," \
      "Table1.Text_Field " \
    "FROM " \
      "Table1;");
    printf("%s\n\n",(szQuery));
    SQLBindCol(hStmt,1,SQL_C_ULONG,&iId,0,&iJnk);
    SQLBindCol(hStmt,2,SQL_C_DOUBLE,&dblNum,0,&iJnk);
    SQLBindCol(hStmt,3,SQL_C_TYPE_DATE,&ts,0,&iJnk);
    SQLBindCol(hStmt,4,SQL_C_CHAR,szString,30,&iJnk);
    puts(" iId      Double           Date           String");
    puts("=====================================================");
    if(SQLExecDirect(hStmt,szQuery,SQL_NTS)==SQL_SUCCESS)
    {
       while(SQLFetch(hStmt)!=SQL_NO_DATA)
       {
        printf("%u\t%f\t%s\t%s\n",iId,dblNum,MkDate(&ts),szString);
       }
    }
    SQLCloseCursor(hStmt);
    SQLFreeHandle(SQL_HANDLE_STMT,hStmt);
    return TRUE;
 }
 //
 return FALSE;
}
//
//
int main(int argc, char *argv[])
{
 SQLCHAR szDBName[24];
 SQL sql;
 //
 strcpy(szDBName,"TestData.mdb");
 if(blnCreateDB(szDBName))
 {
    ODBCConnect(szDBName,&sql);
    if(sql.blnConnected==TRUE)
    {
       puts("We're Connected!");
       if(blnMakeTable(&sql))
       {
          puts("Table1 Successfully Created!");
          if(blnInsert(&sql)==TRUE)
             printf("Data Insertion Successful!\n\n");
          else
             puts("Data Insertion Failure!");
          if(blnDumpData(&sql)==TRUE)
             puts("\nblnDumpData==TRUE");
          else
             puts("\nblnDumpData==FALSE");
       }
       else
          puts("Table Creation Failure!");
       ODBCDisconnect(&sql);
    }
    else
       puts("Connection Failure!");
 }
 else
    puts("Database Creation Failure!");
 system("PAUSE");
 //
 return 0;
}


End of Code. Questions and problems coming up next.
The errors I'm getting :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp||In function `void ODBCConnect(SQLCHAR*, tagSQL*)':|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|39|error: invalid conversion from `SQLCHAR*' to `char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|39|error:   initializing argument 1 of `char* strcpy(char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|45|error: invalid conversion from `SQLCHAR*' to `char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|45|error:   initializing argument 1 of `char* strcat(char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|53|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|53|error:   initializing argument 1 of `size_t strlen(const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp||In function `void InstallerError()':|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|100|error: invalid conversion from `SQLCHAR*' to `CHAR*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|100|error:   initializing argument 3 of `SQLRETURN SQLInstallerError(WORD, DWORD*, CHAR*, WORD, WORD*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|102|warning: unsigned int format, DWORD arg (arg 3)|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp||In function `UINT blnCreateDB(SQLCHAR*)':|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|115|error: invalid conversion from `SQLCHAR*' to `char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|115|error:   initializing argument 1 of `char* strcpy(char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|116|error: invalid conversion from `SQLCHAR*' to `char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|116|error:   initializing argument 1 of `char* strcat(char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|116|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|116|error:   initializing argument 2 of `char* strcat(char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|118|error: invalid conversion from `SQLCHAR*' to `const CHAR*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|118|error:   initializing argument 4 of `BOOL SQLConfigDataSource(HWND__*, WORD, const CHAR*, const CHAR*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp||In function `UINT blnMakeTable(tagSQL*)':|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|138|error: invalid conversion from `SQLCHAR*' to `char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|138|error:   initializing argument 1 of `char* strcpy(char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp||In function `TIMESTAMP_STRUCT ParseDate(SQLCHAR*, SQLCHAR*, SQLCHAR*)':|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|170|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|170|error:   initializing argument 1 of `size_t strlen(const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|184|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|184|error:   initializing argument 1 of `int strcmpi(const char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|186|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|186|error:   initializing argument 1 of `int atoi(const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|190|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|190|error:   initializing argument 1 of `int strcmpi(const char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|192|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|192|error:   initializing argument 1 of `int atoi(const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|196|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|196|error:   initializing argument 1 of `int strcmpi(const char*, const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|198|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|198|error:   initializing argument 1 of `int atoi(const char*)'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|199|error: invalid conversion from `SQLCHAR*' to `const char*'|
C:\Documents and Settings\limhc\My Documents\Visual Studio 2005\WorkExcel\main.cpp|199|error:   initializing argument 1 of `int atoi(const char*)'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 1 warnings ===|


*Some identical erros have been removed to provide space*

The original poster used Visual C++ 6.0. I'm using CodeBlocks. Is that the reason why I'm getting these errors? How do I go about resolving it? What do they mean, exactly? They sound like they're about incompatible data types. Am I correct?

Also, further unrelated question :
When creating a new project, I'm have to choose between different types of applications (eg : Windows Forms Application, Win32 Console Application, ATL Project). What do these mean and how do they impact what I'm doing?

Thank you. Having....so much trouble.

Topic archived. No new replies allowed.