Solved

dbbind error

Posted on 2004-10-09
1
423 Views
Last Modified: 2007-12-19
I get the below error on dbbind when attempting to build the below module.  What could be causing this?

error:
Performing Custom Build Step on .\test.sc
ESQL test.sc:
Compiling...
test.cpp
c:\test\test.cpp(25) : error C2664: 'dbbind' : cannot convert parameter 5 from 'char *' to 'unsigned char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

test.sc:
#define      DBNTWIN32
#include "windows.h"
#include <sqlfront.h>
#include <sqldb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

PDBPROCESS dbproc;
PLOGINREC login;
RETCODE result_code;

char sql_stmt[256];
char testvar[51];

void main() {
  void sqlconn();

  sqlconn();

  sprintf(sql_stmt,"SELECT testvar FROM testtable");
  dbcmd(dbproc,sql_stmt);
  dbsqlexec(dbproc);

  while ((result_code = dbresults(dbproc)) != NO_MORE_RESULTS) {
    if (result_code == SUCCEED) {
        dbbind (dbproc,1,NTBSTRINGBIND,(DBINT) 0,(char *) testvar);

        while (dbnextrow(dbproc) != NO_MORE_ROWS) {
          fprintf(stdout,"testvar: %s\n",testvar);
        }
      }
  }
}

/* sqlconn procedure */

void sqlconn() {
  if (dbinit() == (char *)NULL) {
      fprintf(stdout,"Communications layer not loaded!\n");
      return;
  }

  login = dblogin();
  DBSETLUSER(login,(char *)"testlogin");
  DBSETLAPP(login,(char *)"testapp");
  DBSETLPWD(login,(char *)"testpwd");
  DBSETLVERSION(login,DBVER60);

  if ((dbproc = dbopen(login,"testsvr")) == NULL) {
      fprintf(stdout,"dbopen failed!\n");
      return;
  }

  dbuse(dbproc,"testdb");
  fprintf(stdout,"Success!\n");

} /* end sqlconn procedure */
0
Comment
Question by:arichexe
1 Comment
 
LVL 15

Accepted Solution

by:
efn earned 125 total points
ID: 12269196
The fifth parameter to dbbind is declared as LPBYTE.  (I assume you are using the dbbind from the Microsoft SQL Server DB-Library.)  LPBYTE is a pointer to a BYTE.  A BYTE is an unsigned char.  So the parameter type is unsigned char*.  You are passing a pointer to char, not unsigned char, as this parameter, and that's not close enough for the compiler.  The simplest fix would be to declare the testvar array as an array of unsigned char.  Then you could just use its name as the parameter, without a cast, and the compiler would be satisfied.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now