-
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";
}
-
Change your char return type to char*
-
**** 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*
-
row is of type char** so you'd have to change the return type to char** for that one.
-
Works great :) Thanks so much
Only too bad that there doesnt seem to be any support for fetching arrays like in php
-
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
-
I don't know anything about .dll but I would say that has something to do with a .lib that needs to be linked.
-
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
-
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.
-
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?
-
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.
-
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.
-
Segementation fault? Your OS clearly doesn't like something your doing in the program.
-
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.
-
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.