PDA

View Full Version : A clean embedded mysql example for VC++ 6.0 please!


d98rolb
04-08-2003, 12:21 PM
Hi, I try to use libmysqld.dll from C, but I crash my program when I run
this code.
Any help would be great!


/* A Win32 application in Visual C++ is defined */
#include "stdafx.h"
#include <Windows.h>
#include <Winbase.h>

typedef int (CALLBACK* SERVER_INIT_FPTR)(int, char **, char **);
typedef void (CALLBACK* SERVER_END_FPTR)(void);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
SERVER_INIT_FPTR mysql_server_init;
SERVER_END_FPTR mysql_server_end;

// As this is just a test, hardcoding is ok
LPCTSTR dlldir = "D:\\Program\\mysql\\Embedded\\DLL\\release\\libmysqld.dll";
HMODULE mysql_dll;

if(mysql_dll = LoadLibrary(dlldir))
{
mysql_server_init = (SERVER_INIT_FPTR) GetProcAddress(mysql_dll, "mysql_server_init");
mysql_server_end = (SERVER_END_FPTR) GetProcAddress(mysql_dll, "mysql_server_end");

// Crash: Unhandled exception in mysql.exe (LIBMYSQLD.DLL):
0xC0000005: Access violation
mysql_server_init(0, NULL, NULL);
mysql_server_end();
FreeLibrary(mysql_dll);
}
return 0;
}


Here is the doc for mysql_server_init():

"The NULL-terminated list of strings in groups selects which groups in the option files will be active. See section 4.1.2 `my.cnf' Option Files. For convenience, groups may be NULL, in which case the [server] and [emedded] groups will be active. "

So I thought it may be ok to send NULL as arguments to
mysql_server_init(). Here are my "C:\winnt\my.ini" file:

#This File was made using the WinMySQLAdmin 1.4 Tool
#2003-03-25 16:23:20

#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions

[mysqld]
basedir=D:/Program/mysql
#bind-address=192.168.0.2
datadir=D:/Program/mysql/data
#language=D:/Program/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
#set-variable=key_buffer=16M

[WinMySQLadmin]
Server=D:/Program/mysql/bin/mysqld-nt.exe
QueryInterval=10

[server]
language=D:\Program\mysql\share\swedish

[emedded]

I don't know really what to write at the [server] and the [embedded] groups at this stage. I hope this isn't the reason for the crash.

Regards Roland