Hello,
For some reason, which my reason doesn't know, my WAMP-mySQL server continues to accept connections from the Lazarus IDE, and from PhpMyAdmin, but now refuses connections from a binary compiled with Lazarus (even if I close Lazarus before running Project1.exe; Cf. attached screenshot)
. It's all the more annoying, as PhpMyAdmin continues to work via its Ajax-based-dll-PDO client.
So, i'm trying to understand if it's mysql_init, mysql_options or mysql_real_connect, which is the culprit. I've searched on the web: I found this problem many times. But nothing that pinpoints precisely where the problem lies (I've no firewall, only one libmysql.dll on my PC, etc).
Now, i'm looking at the file mariadb_lib.c on
https://github.com/mariadb-corporation/mariadb-connector-c/tree/3.1/libmariadb. This function takes a pointer to a structure as parameter: if this pointer is NULL in C++ language i.e. nil in Pascal language, then a malloc is made and the function simply returns the validly assigned pointer from the address of the structure loaded in the heap. That's all
I load the library like this..:
var
hFLib: TLibHandle;
begin
hFLib:= Dynlibs.SafeLoadLibrary ('C:\Windows\System32\libmysql.dll');
end;
...and it works. I see (Cf. the screenshot) that the library is loaded i.e. a copy of the code of this library is linked to Project1.exe.
Then, I'm trying to call mysql_init like this...:
uses
mysql57dyn;
...\...
var
HMySQL: PMySQL;
begin
HMySQL:= nil;
HMySQL:= mysql57dyn.mysql_init(nil);
if not Assigned(HMySQL) then
ShowMessage('HMySQL is not assigned')
else
ShowMessage('HMySQL is assigned');
...and i've an access violation. In fact, looking at mysql.inc, i guess that
var ...\... mysql_init: function (mysql:PMYSQL):PMYSQL;extdecl; is a kind of way to declare a pointer to a library routine (I don't know this syntax). My problem seems to be that the way i call it or the moment i call it, it doesn't point at anything at all.
In fact, i would like to call this routine via its
external+ name conventional (for me) declaration i.e. to call:
function mysql_init(mysql:PMYSQL):PMYSQL;extdecl;external mysqllib name 'mysql_init';
However, all external declarations, already present in mysql.inc, are conditioned with
{$IFNDEF LinkDynamically}. But if I add
uses mysql57dyn; to my project, I implicitly add
{$DEFINE LinkDynamically}.
==> Does anyone know how to:
- use the structures imported from the *.h files in mysql.inc
- and use the external
external+ name function declarations
?