Re: HELP mysql_server_init embedded in a DLL?
Hi, - Original Message - From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, February 28, 2003 9:09 PM Subject: Re: HELP mysql_server_init embedded in a DLL? Attempts at creating an embedded mySQL DLL for VB: I can successfully use the mysql_init() function from libmysql.lib to create a DLL for VB. However, when I use this function (in a DLL or lib)linked against the libmysqld.lib or mysqlserver.lib it crashes the VB application but not the C application. I tried hard coding the arguments and servergroups for mysql_server_init (I also used memset to initialize the strings to 0), I get the same result. The lib I create will always work with a C program, but the DLL will not work with VB. You must take care with CALLING CONVENTIONS(__stdcall).This is be one reason for crash. Does anyone have any more suggestions on how to use the embedded library in a Visual C DLL to link with VB? You can not access directly the mysql api function from VB.Are ,at least,two big problems :the VB type STRING which is UNICODE ; passing the data structure (like MYSQL which contain node lists) from VB to C or reverse.In my opinion you should make functions which will be interface between MYSQL C API and VB.Also you should make your own function to convert char to unicode and reverse.It's better if you don't use MultiByteToWideChar()...you will get a lot of unpleasure surprises. Of course you can do some improvisation (like in mysql_init or to convert a STRING into ARRAY of BYTE) but is not a solution because VB imediatly will give you some error like OUT OF MEMORY. Regards, Gelu _ G.NET SOFTWARE COMPANY Permanent e-mail address : [EMAIL PROTECTED] [EMAIL PROTECTED] Thanks Eric p.s: Email received from another individual (Thanks!!): Put the libMySql.dll in the wint\system32 directory (or in the directory where your executable is!) In vb, I use this one the declares: Public Declare Function mysql_init Lib libmySQL (ByVal lMYSQL As Long) As Long Public Declare Function mysql_real_connect Lib libmySQL _ (ByVal lMYSQL As Long, _ ByVal sHostName As String, _ ByVal sUserName As String, _ ByVal sPassword As String, _ ByVal sDbName As String, _ ByVal lPortNum As Long, _ ByVal sSocketName As String, _ ByVal lFlags As Long) As Long Public Function OpenConnection(ByVal sHostName As String, _ ByVal sUserName As String, _ ByVal sPassword As String, _ ByVal sDbName As String, _ Optional ByVal lPortNum As Long = 3306, _ Optional ByVal lFlags As MYSQL_FLAG) As MYSQL_CONNECTION_STATE mlMYSQL = mysql_init(mlMYSQL) If mlMYSQL = 0 Then no connection handler Else 'connect to server If mysql_real_connect(mlMYSQL, msHostname, msUsername, msPassword, msDbName, mlPortNum, , mlFlags) = 0 Then ' oops Else 'connection established ... state is now open End If End If 'setup the return value End Function I myselve created an dll (in vb) which encapsulates all the stuff to connect to the database, use recordsets, (as close as possible to the ADO object model: so with connection, recordset - objects, bookmarks, fields, ...) Hope this helps. From: Gelu Gogancea [EMAIL PROTECTED] To: Derick Smith [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED] Subject: Re: HELP mysql_server_init embedded in a DLL? Date: Fri, 28 Feb 2003 14:40:31 +0200 Hi, - Original Message - From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, February 27, 2003 10:33 PM Subject: Re: HELP mysql_server_init embedded in a DLL? I am posting this again, in hope that I will get a response. I tried doing the following (see VB code below. I got this code from another site): I get the same error message as if I was calling the DLL I created in C which calls mysql_server_init. Is it impossible to call this function from VB or embedded in another DLL from VB? Can I only use the embedded mysql library in C or C++? Thanks Eric Public Declare Function mysql_server_init Lib C:\mysql40\source\lib_release\libmysqld.dll _ (ByVal argc As Long, _ ByVal argv As Byte, _ ByVal groups As Byte) As Long Private Sub cmdmysq_server_init_Click() Dim argv(0) As Byte, groups(0) As Byte Dim i As Long argv(0) = Asc(0) groups(0) = Asc(0) i = mysql_server_init(0, argv, groups) End Sub In my opinion,this will never work because argv and groups are pointed to array which have a pointer char
Re: HELP mysql_server_init embedded in a DLL?
Hi, - Original Message - From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, February 27, 2003 10:33 PM Subject: Re: HELP mysql_server_init embedded in a DLL? I am posting this again, in hope that I will get a response. I tried doing the following (see VB code below. I got this code from another site): I get the same error message as if I was calling the DLL I created in C which calls mysql_server_init. Is it impossible to call this function from VB or embedded in another DLL from VB? Can I only use the embedded mysql library in C or C++? Thanks Eric Public Declare Function mysql_server_init Lib C:\mysql40\source\lib_release\libmysqld.dll _ (ByVal argc As Long, _ ByVal argv As Byte, _ ByVal groups As Byte) As Long Private Sub cmdmysq_server_init_Click() Dim argv(0) As Byte, groups(0) As Byte Dim i As Long argv(0) = Asc(0) groups(0) = Asc(0) i = mysql_server_init(0, argv, groups) End Sub In my opinion,this will never work because argv and groups are pointed to array which have a pointer char*(*); But anyhow...if you wish to try again this formula, must declare argv and groups ByRef because VB is responsable for the stack and the variable must be initialized before using like argument in function.Since argv and groups are byte is a non-sense to use ASC(). I'm very pessimistic that will be work. From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: mysql_server_init embedded in a DLL? Date: Wed, 26 Feb 2003 14:34:28 + Hi! I am trying to create a DLL that will hide embedded mySQL functions for use with VB. I am using mysqlserver.lib. I am able to compile and execute the following code. This has to be done in C because VB is too slow :-( If mysql_server_init function is run in the DLL from Visual Basic. I get the following error message: ..referenced memory at 0x00. The memory could not be read. Without the mysql_server_init function it will run correctly. It will also run correctly when this is compiled as a .lib file linked to a C program. Is it possible to embed mysql_server_init in a DLL? (So the DLL can be used in VB) Thanks in advance for any responses. Thanks Eric header1.h #define GPAPI __stdcall header2.h typedef unsigned long DBS; #define NULLDBS (DBS)0 api.c GPAPI DBS dbNewSet (char * basedir, char * datadir, char * dbname) { return NewSet(basedir,datadir,dbname); } newset.c extern DBS NewSet(char * basedir, char * datadir, char * dbname) { DBSET* pSet = CreateSet(); char *args[3]; char strArgs[3][1024]; I guess some problems can be elimanted if you initialize the variables which are declared or if you allocate some memory. Anyhow you can use '\0' - termination string to be sure that you don't have *other garbage* after your string.This *garbage* can influence the lenght of the string.Bad thing. int iRtn; int argc = 3; strcpy(strArgs[0],this_program); sprintf(strArgs[1],--basedir=%s,basedir); sprintf(strArgs[2],--datadir=%s,datadir); args[0]= strArgs[0]; args[1]= strArgs[1]; args[2]= strArgs[2]; /* If I comment out this line of code, the DLL will run correctly. If mysql_server_init function is run in the DLL. I get the following error message: ..referenced memory at 0x00. The ...this means that one of your variables is NULL.This error occur because you don't *catch* the right pointer.By using equal sign you pass the pointer to lvalue and not the value.At the address of pointer you can find the value. memory could not be read */ iRtn = mysql_server_init(3, args, server_groups); if (pSet ==0 ) return NULLDBS; memset(pSet, 0, sizeof(DBSET)); /* Zero the structure.*/ pSet-size = sizeof(DBSET);/* Assign structure size. */ pSet-magic = DBS_MAGIC; /* Assign magic number. */ return (DBS)(void*)pSet; } If you have a little patience (maybe a week or two...i try to find some available time for this) a new version of GMySQL(An interface between MYSQL C API function and VB or other development platform for Windows) will be released.This new version, will contain the implementation of the new replication functions and also will be able to work with libmysqld. Regards, Gelu _ G.NET SOFTWARE COMPANY Permanent e-mail address : [EMAIL PROTECTED] [EMAIL PROTECTED] _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail
Re: HELP mysql_server_init embedded in a DLL?
Attempts at creating an embedded mySQL DLL for VB: I can successfully use the mysql_init() function from libmysql.lib to create a DLL for VB. However, when I use this function (in a DLL or lib)linked against the libmysqld.lib or mysqlserver.lib it crashes the VB application but not the C application. I tried hard coding the arguments and servergroups for mysql_server_init (I also used memset to initialize the strings to 0), I get the same result. The lib I create will always work with a C program, but the DLL will not work with VB. Does anyone have any more suggestions on how to use the embedded library in a Visual C DLL to link with VB? Thanks Eric p.s: Email received from another individual (Thanks!!): Put the libMySql.dll in the wint\system32 directory (or in the directory where your executable is!) In vb, I use this one the declares: Public Declare Function mysql_init Lib libmySQL (ByVal lMYSQL As Long) As Long Public Declare Function mysql_real_connect Lib libmySQL _ (ByVal lMYSQL As Long, _ ByVal sHostName As String, _ ByVal sUserName As String, _ ByVal sPassword As String, _ ByVal sDbName As String, _ ByVal lPortNum As Long, _ ByVal sSocketName As String, _ ByVal lFlags As Long) As Long Public Function OpenConnection(ByVal sHostName As String, _ ByVal sUserName As String, _ ByVal sPassword As String, _ ByVal sDbName As String, _ Optional ByVal lPortNum As Long = 3306, _ Optional ByVal lFlags As MYSQL_FLAG) As MYSQL_CONNECTION_STATE mlMYSQL = mysql_init(mlMYSQL) If mlMYSQL = 0 Then no connection handler Else 'connect to server If mysql_real_connect(mlMYSQL, msHostname, msUsername, msPassword, msDbName, mlPortNum, , mlFlags) = 0 Then ' oops Else 'connection established ... state is now open End If End If 'setup the return value End Function I myselve created an dll (in vb) which encapsulates all the stuff to connect to the database, use recordsets, (as close as possible to the ADO object model: so with connection, recordset - objects, bookmarks, fields, ...) Hope this helps. From: Gelu Gogancea [EMAIL PROTECTED] To: Derick Smith [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED] Subject: Re: HELP mysql_server_init embedded in a DLL? Date: Fri, 28 Feb 2003 14:40:31 +0200 Hi, - Original Message - From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, February 27, 2003 10:33 PM Subject: Re: HELP mysql_server_init embedded in a DLL? I am posting this again, in hope that I will get a response. I tried doing the following (see VB code below. I got this code from another site): I get the same error message as if I was calling the DLL I created in C which calls mysql_server_init. Is it impossible to call this function from VB or embedded in another DLL from VB? Can I only use the embedded mysql library in C or C++? Thanks Eric Public Declare Function mysql_server_init Lib C:\mysql40\source\lib_release\libmysqld.dll _ (ByVal argc As Long, _ ByVal argv As Byte, _ ByVal groups As Byte) As Long Private Sub cmdmysq_server_init_Click() Dim argv(0) As Byte, groups(0) As Byte Dim i As Long argv(0) = Asc(0) groups(0) = Asc(0) i = mysql_server_init(0, argv, groups) End Sub In my opinion,this will never work because argv and groups are pointed to array which have a pointer char*(*); But anyhow...if you wish to try again this formula, must declare argv and groups ByRef because VB is responsable for the stack and the variable must be initialized before using like argument in function.Since argv and groups are byte is a non-sense to use ASC(). I'm very pessimistic that will be work. From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: mysql_server_init embedded in a DLL? Date: Wed, 26 Feb 2003 14:34:28 + Hi! I am trying to create a DLL that will hide embedded mySQL functions for use with VB. I am using mysqlserver.lib. I am able to compile and execute the following code. This has to be done in C because VB is too slow :-( If mysql_server_init function is run in the DLL from Visual Basic. I get the following error message: ..referenced memory at 0x00. The memory could not be read. Without the mysql_server_init function it will run correctly. It will also run correctly when this is compiled as a .lib file linked to a C program. Is it possible to embed mysql_server_init in a DLL? (So the DLL can be used in VB) Thanks in advance for any responses. Thanks Eric header1.h #define GPAPI __stdcall header2.h typedef unsigned long DBS; #define NULLDBS (DBS)0 api.c GPAPI DBS dbNewSet (char * basedir, char
Re: HELP mysql_server_init embedded in a DLL?
I am posting this again, in hope that I will get a response. I tried doing the following (see VB code below. I got this code from another site): I get the same error message as if I was calling the DLL I created in C which calls mysql_server_init. Is it impossible to call this function from VB or embedded in another DLL from VB? Can I only use the embedded mysql library in C or C++? Thanks Eric Public Declare Function mysql_server_init Lib C:\mysql40\source\lib_release\libmysqld.dll _ (ByVal argc As Long, _ ByVal argv As Byte, _ ByVal groups As Byte) As Long Private Sub cmdmysq_server_init_Click() Dim argv(0) As Byte, groups(0) As Byte Dim i As Long argv(0) = Asc(0) groups(0) = Asc(0) i = mysql_server_init(0, argv, groups) End Sub From: Derick Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: mysql_server_init embedded in a DLL? Date: Wed, 26 Feb 2003 14:34:28 + Hi! I am trying to create a DLL that will hide embedded mySQL functions for use with VB. I am using mysqlserver.lib. I am able to compile and execute the following code. This has to be done in C because VB is too slow :-( If mysql_server_init function is run in the DLL from Visual Basic. I get the following error message: ..referenced memory at 0x00. The memory could not be read. Without the mysql_server_init function it will run correctly. It will also run correctly when this is compiled as a .lib file linked to a C program. Is it possible to embed mysql_server_init in a DLL? (So the DLL can be used in VB) Thanks in advance for any responses. Thanks Eric header1.h #define GPAPI __stdcall header2.h typedef unsigned long DBS; #define NULLDBS (DBS)0 api.c GPAPI DBS dbNewSet (char * basedir, char * datadir, char * dbname) { return NewSet(basedir,datadir,dbname); } newset.c extern DBS NewSet(char * basedir, char * datadir, char * dbname) { DBSET* pSet = CreateSet(); char*args[3]; char strArgs[3][1024]; int iRtn; int argc = 3; strcpy(strArgs[0],this_program); sprintf(strArgs[1],--basedir=%s,basedir); sprintf(strArgs[2],--datadir=%s,datadir); args[0]= strArgs[0]; args[1]= strArgs[1]; args[2]= strArgs[2]; /* If I comment out this line of code, the DLL will run correctly. If mysql_server_init function is run in the DLL. I get the following error message: ..referenced memory at 0x00. The memory could not be read */ iRtn = mysql_server_init(3, args, server_groups); if (pSet ==0 ) return NULLDBS; memset(pSet, 0, sizeof(DBSET)); /* Zero the structure.*/ pSet-size = sizeof(DBSET);/* Assign structure size. */ pSet-magic = DBS_MAGIC; /* Assign magic number. */ return (DBS)(void*)pSet; } _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php