Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 03/01/26 16:40
WFO Training with parallel cores Zorro64
by Martin_HH. 02/26/26 16:03
Zorro version 3.0 prerelease!
by TipmyPip. 02/25/26 16:38
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (USER0328, Quad), 5,448 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
the1, alx, ApprenticeInMuc, PatrickH90, USER0328
19200 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Import full struct from DLL to C-Lite #390079
12/22/11 09:56
12/22/11 09:56
Joined: Dec 2011
Posts: 15
Germany
W
Waldnebel Offline OP
Newbie
Waldnebel  Offline OP
Newbie
W

Joined: Dec 2011
Posts: 15
Germany
Hi...
I got a complex STRUCT on a DLL (written in c++) and want to import it to C-Lite (Need it to run a Function)

So my Question is: is it possible to import the full struct from DLL to C-Lite?
Anybody a idea?

Best regards
Waldnebel

Re: Import full struct from DLL to C-Lite [Re: Waldnebel] #390082
12/22/11 10:25
12/22/11 10:25
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Yes. I do this all the time. Just copy the struct definition to Lite-C and thats it. Pass back a pointer to it and then access the struct fields.

Re: Import full struct from DLL to C-Lite [Re: HeelX] #390083
12/22/11 10:28
12/22/11 10:28
Joined: Dec 2011
Posts: 15
Germany
W
Waldnebel Offline OP
Newbie
Waldnebel  Offline OP
Newbie
W

Joined: Dec 2011
Posts: 15
Germany
Only at this way to import the "realy complex" struct to C-Lite?
its a MySQL connect struct...
That will be hard work...

Re: Import full struct from DLL to C-Lite [Re: Waldnebel] #390084
12/22/11 10:35
12/22/11 10:35
Joined: Dec 2011
Posts: 15
Germany
W
Waldnebel Offline OP
Newbie
Waldnebel  Offline OP
Newbie
W

Joined: Dec 2011
Posts: 15
Germany
I will correct: Its impossible ><

Re: Import full struct from DLL to C-Lite [Re: Waldnebel] #390091
12/22/11 12:59
12/22/11 12:59
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
I did it with mysql, it should work just fine.


Click and join the 3dgs irc community!
Room: #3dgs
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
W
Waldnebel Offline OP
Newbie
Waldnebel  Offline OP
Newbie
W

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:
Code:
// 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:

Code:
...

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 Offline
Expert
WretchedSid  Offline
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
W
Waldnebel Offline OP
Newbie
Waldnebel  Offline OP
Newbie
W

Joined: Dec 2011
Posts: 15
Germany
The struct is from mysql.h and realy complex... (struct in struct... etc..)
Example:
Code:
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 Offline
Expert
WretchedSid  Offline
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
W
Waldnebel Offline OP
Newbie
Waldnebel  Offline OP
Newbie
W

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

Code:
#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:

Code:
...
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.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1