|
2 registered members (USER0328, Quad),
5,448
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Import full struct from DLL to C-Lite
[Re: Joozey]
#390093
12/22/11 13:19
12/22/11 13:19
|
Joined: Dec 2011
Posts: 15 Germany
Waldnebel
OP
Newbie
|
OP
Newbie
Joined: Dec 2011
Posts: 15
Germany
|
Ok... I'm working now for 2 weeks on a DLL to connect a MySQL server... On C++ it works fine... But i'm not able to use it in C-Lite. Here is my MySQL Dll script:
// gs_mysql.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include <stdafx.h>
#define DLL_USE
#include "my_global.h"
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <io.h>
#include <time.h>
#include <windows.h>
#include <windef.h>
#include "var.h" // the var class - without it, you'd need _VAR() macros
#include "adll.h"
#include "mysql.h" // MySQL Include File
MYSQL* testcon;
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved) // this is where the DLL first starts.
{
engine_bind();
return TRUE;
}
MYSQL* gs_mysql_init()
{
MYSQL *connect; // Create a pointer to the MySQL instance
connect=mysql_init(NULL); // Initialise the instance
return connect;
}
MYSQL* gs_mysql_connect(MYSQL * gs_connect, const char *server, const char *user, const char *password, const char *database)
{
// Struct für Connection
gs_connect=mysql_real_connect(gs_connect,server,user,password,database,0,NULL,0);
return gs_connect;
}
MYSQL_RES* gs_mysql_query(MYSQL* gs_connect, const char* abfrage)
{
MYSQL_RES *result; // Struct für abfrageresults
mysql_query(gs_connect, abfrage); // Abfrage
return result = mysql_store_result(gs_connect); // Speichere Abfrageergebnisse in res_set und gib sie zurück
}
my_ulonglong gs_mysql_num_rows(MYSQL_RES *result)
{
my_ulonglong numrows = mysql_num_rows(result); //Counter für alle Reihen
return numrows;
}
my_ulonglong gs_mysql_num_field(MYSQL_RES *result)
{
my_ulonglong numfields = mysql_num_fields(result); //Counter für alle Spalten
return numfields;
}
MYSQL_ROW gs_mysql_fetch_row(MYSQL_RES *result)
{
return mysql_fetch_row(result);
}
void gs_mysql_close(MYSQL*gs_connect)
{
return mysql_close(gs_connect);
}
And here in Lite-C:
...
var gs_mysql_init();
var gs_mysql_connect(var gs_connect, STRING server, STRING user, STRING password, STRING database);
var gs_mysql_query(var gs_connect, var abfrage);
...
function main()
{
video_screen = 2; // start window mode
video_mode =8;
screen_color.blue = 150;
login_pannel(1);
mouse_mode = 4; // show the mouse pointer
mouse_map = cursor_pcx; // set the mouse pointer bitmap
var testx = gs_mysql_init();
testx = gs_mysql_connect (testx,"localhost","root","","cdcol");
var resultat;
resultat = gs_mysql_query(testx, "select * from cds");
...
My table has teeth marks already ><
|
|
|
Re: Import full struct from DLL to C-Lite
[Re: Waldnebel]
#390097
12/22/11 14:10
12/22/11 14:10
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
You are casting around types that aren't meant to be casted around. For example, a STRING is not a const char * and neither is a var! And last but not least, I don't see any struct in your code. Where is it?
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Import full struct from DLL to C-Lite
[Re: WretchedSid]
#390099
12/22/11 14:18
12/22/11 14:18
|
Joined: Dec 2011
Posts: 15 Germany
Waldnebel
OP
Newbie
|
OP
Newbie
Joined: Dec 2011
Posts: 15
Germany
|
The struct is from mysql.h and realy complex... (struct in struct... etc..) Example:
typedef struct st_mysql
{
NET net; /* Communication parameters */
unsigned char *connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
char *info, *db;
struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
my_ulonglong extra_info; /* Not used */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag,server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count;
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
my_bool reconnect; /* set to 1 if automatic reconnect */
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
/*
Set if this is the original connection, not a master or a slave we have
added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
*/
my_bool rpl_pivot;
/*
Pointers to the master, and the next slave connections, points to
itself if lone connection.
*/
struct st_mysql* master, *next_slave;
struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
/* needed for send/read/store/use result to work correctly with replication */
struct st_mysql* last_used_con;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
void *thd;
/*
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
from mysql_stmt_close if close had to cancel result set of this object.
*/
my_bool *unbuffered_fetch_owner;
/* needed for embedded server - no net buffer to store the 'info' */
char *info_buffer;
void *extension;
} MYSQL;
Last edited by Waldnebel; 12/22/11 14:19.
|
|
|
Re: Import full struct from DLL to C-Lite
[Re: Waldnebel]
#390101
12/22/11 14:24
12/22/11 14:24
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Well, in case you need to mutate the struct, just build it the way you need it and fill the gaps with padding bytes. Otherwise simply pass a void* pointer and generate the struct only in the DLL.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Import full struct from DLL to C-Lite
[Re: WretchedSid]
#390106
12/22/11 15:11
12/22/11 15:11
|
Joined: Dec 2011
Posts: 15 Germany
Waldnebel
OP
Newbie
|
OP
Newbie
Joined: Dec 2011
Posts: 15
Germany
|
Now i hate MySQL... >< Head -> Table Ach Sid... ich seh gerade du kommst aus Deutschland? Ich komm an dem punkt einfach nit mehr weiter... Hab nun versucht ne einzelne DLLFUNC zu schreiben, indem er einfach Daten von einem vordefinierten Server abruft und in einem Array zurückgibt... Aber dieses Crasht immer in der Main und sagt mir auch noch "Empty Function in main". Irgendwelche Ideen? Hier der Code (C++) - Lässt sich auch ohne Probleme compiliern
#include "mysql.h" // MySQL Include File
#define SERVER "localhost"
#define USER "root"
#define PASSWORD ""
#define DATABASE "cdcol"
MYSQL* testcon;
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved) // this is where the DLL first starts.
{
engine_bind();
return TRUE;
}
DLLFUNC const char gs_mysqltest(const char *abfrage)
{
MYSQL *connect; // Create a pointer to the MySQL instance
connect=mysql_init(NULL); // Initialise the instance
connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0);
MYSQL_RES *res_set; /* Create a pointer to recieve the return value.*/
MYSQL_ROW row; /* Assign variable for rows. */
mysql_query(connect,abfrage);
unsigned int i = 0; /* Create a counter for the rows */
res_set = mysql_store_result(connect); /* Receive the result and store it in res_set */
my_ulonglong numrows = mysql_num_rows(res_set); /* Create the count to print all rows */
/* This while is to print all rows and not just the first row found, */
const char *testxx;
while ((row = mysql_fetch_row(res_set)) != NULL){
testxx=row[0];
return *testxx;
}
mysql_close(connect); /* Close and shutdown */
return *testxx;
}
und in C-Lite:
...
const char gs_mysqltest(const char* abfrage);
...
const char *ausgabe;
ausgabe=gs_mysqltest("select * from cds");
...
Last edited by Waldnebel; 12/22/11 15:18.
|
|
|
|