Just nu i M3-nätverket
Jump to content

Ett litet exempel på embedded mysql för VC++ 6.0?


Roland Bengtsson

Recommended Posts

Roland Bengtsson

Jag försöker använda libmysqld.dll från C, men mitt program kraschar när jag kör den här koden. Jag skulle bli tacksam för hjälp!

 

/* 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;

 // Hårdkodning ok, bara ett testprogram
 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;
}

Här är ett utdrag från dokumentationen för 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. "

 

Så jag tänket det kan vara ok att skicka NULL som argument till mysql_server_init(). Här är min "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]

 

Jag vet int vad jag ska lägga till under [server] och [embedded] grupperna. Men det kan väl inte vara orsaken till kraschen?

 

/Roland

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...