Using functions?

This is a discussion on Using functions? within the C++ Programming forums, part of the General Programming Boards category; Hi, im trying to make a dll to access a mysql server via VB6. But im getting the following errors: ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    17

    Using functions?

    Hi, im trying to make a dll to access a mysql server via VB6.

    But im getting the following errors:

    Code:
    Deleting intermediate files and output files for project 'mysql - Win32 Debug'.
    --------------------Configuration: mysql - Win32 Debug--------------------
    Compiling...
    main.cpp
    c:\cplusplus projects\mysql\main.cpp(17) : error C2440: 'return' : cannot convert from 'char [17]' to 'char'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    c:\cplusplus projects\mysql\main.cpp(23) : error C2440: 'return' : cannot convert from 'char [17]' to 'char'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    c:\cplusplus projects\mysql\main.cpp(30) : error C2440: 'return' : cannot convert from 'char ** ' to 'char'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    c:\cplusplus projects\mysql\main.cpp(35) : error C2440: 'return' : cannot convert from 'char [18]' to 'char'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Error executing cl.exe.
    
    mysql.dll - 4 error(s), 0 warning(s)
    This is my code:
    Code:
    #include <winsock.h>
    #include <mysql.h>
    #include <stdio.h>
    
    char connecttoserver(char *server, char *user, char *password, char *database);
    char sendquery(char *query);
    char fetchresult();
    char closeconn();
    
       MYSQL *conn;
       MYSQL_RES *res;
       MYSQL_ROW row;
    
       char connecttoserver(char *server, char *user, char *password, char *database) {
    	conn = mysql_init(NULL);
    		if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
    			return "Error connecting";
    		}
       }
    
       char sendquery(char *query) {
    	if (mysql_query(conn, query)) {
    		return "Error with query";
    	}
       }
    
       char fetchresult() {
    	res = mysql_use_result(conn);
    	while ((row = mysql_fetch_row(res)) != NULL)
    	return row;
       }
    
       char closeconn() {
    	mysql_close(conn);
    	return "Connection closed";
       }

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    Change your char return type to char*

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    **** i fixed most of it but still havent got it.. im sry for these noobish questions

    Code:
    #include <winsock.h>
    #include <mysql.h>
    #include <stdio.h>
    
    char* connecttoserver(char *server, char *user, char *password, char *database);
    char* sendquery(char *query);
    char fetchresult();
    char* closeconn();
    
       MYSQL *conn;
       MYSQL_RES *res;
       MYSQL_ROW row;
    
       char* connecttoserver(char *server, char *user, char *password, char *database) {
    	conn = mysql_init(NULL);
    		if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
    			return "Error connecting";
    		}
       }
    
       char* sendquery(char *query) {
    	if (mysql_query(conn, query)) {
    		return "Error with query";
    	}
       }
    
       char fetchresult() {
    	res = mysql_use_result(conn);
    	while ((row = mysql_fetch_row(res)) != NULL) 
    	return row;
       }
    
       char* closeconn() {
    	mysql_close(conn);
    	return "Connection closed";
       }
    error:
    Code:
    --------------------Configuration: mysql - Win32 Debug--------------------
    Compiling...
    main.cpp
    C:\CPlusPlus Projects\mysql\main.cpp(30) : error C2440: 'return' : cannot convert from 'char ** ' to 'char'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Error executing cl.exe.
    
    mysql.dll - 1 error(s), 0 warning(s)
    I keep getting the same error, even if i put char*
    Last edited by Diod; 02-13-2006 at 01:39 PM.

  4. #4
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    row is of type char** so you'd have to change the return type to char** for that one.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    Works great Thanks so much

    Only too bad that there doesnt seem to be any support for fetching arrays like in php

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    Hmm when i implement it into my vb project, and i try to run my project it says:

    Can't find DLL entry point connect in mysql.dll

    I implement it this way in vb:

    Code:
    Private Declare Function connect Lib "mysql.dll" (server, user, password, database)
    Private Declare Function query Lib "mysql.dll" (query)
    Private Declare Function fetch_row Lib "mysql.dll" ()
    Private Declare Function closeconn Lib "mysql.dll" ()
    The mysql.dll is in the same folder as in the exe that was made by VB

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    I don't know anything about .dll but I would say that has something to do with a .lib that needs to be linked.
    Sent from my iPad«

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    It does say "LINK : warning LNK4089: all references to "LIBMYSQL.dll" discarded by /OPT:REF" when it compiles it.
    Thats the release compile. But when i compile under "debug" it doesnt give an error, but it doesnt even find it when i try to access it with vb

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    When you downloaded the mySQL libraries did it come with a mysql.lib? That's an import library. From what I know, it basically tells the program where to look in the DLL to get the stuff it needs. It needs to be in the project when you compile.
    Sent from my iPad«

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    I have all the necessery links made, ive even successfully tested its functions in a c++ program. The only thing i now need is for the dll to work.
    Do i need to put constructors and destructors and all of those things in a dll project?

  11. #11
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    no, you need to link against the lib file which either comes with the dll or can be generated using something like implib.
    After that, the OS kernel should take care of things at runtime.

  12. #12
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    Ive found the problem:
    The problem was in my vb code, i had the wrong function names declared, sorry, that was stupid, but now i face another problem.
    When i try to use a function, my program just ends. And if i try to run it in the VB environment itself, it closes down visual basic. While there is no single code of ending the program, not in the DLL nor exe.

  13. #13
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Segementation fault? Your OS clearly doesn't like something your doing in the program.
    Sent from my iPad«

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    A segmentation fault is when your program accesses memory that doesn't belong to it. You can use a debugger/cout statements to find out where it seg faults.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Oh, I wasn't asking. That "Segmentation fault?" was meant to be read as "Maybe it's a segmentation fault" hence the reason the program is crashing abruptly, aye.
    Sent from my iPad«

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21