I'm loading a libmysql.dll and want to connect to a db. When calling the mysql_real_connect i get a buffer overflow error. Why? Code:
#include <iostream>
#include <string.h>
#include <windows.h>
#include <cstdlib>
#include <stdio.h>
#include "mysql.h"
using namespace std;
// Definition des Types der DLL-Funktion, die verwendet werden soll
typedef int (*BinaryFunction_c) (int,string,string,string,string,int,int,int) ;
typedef int (*BinaryFunction_i) (int) ;
int main (void)
{
BinaryFunction_i m_init ;
BinaryFunction_c m_connect ;
BOOL fFreeResult ;
int sqlinit;
int connid;
// DLL Datei laden
HINSTANCE hinstLib = LoadLibrary("./libmysql.dll");
if (hinstLib != NULL)
{
// Die Einsprungadresse abfragen
m_init = (BinaryFunction_i) GetProcAddress (hinstLib, "mysql_init") ;
// Die Funktion aufrufen
if ( m_init != NULL )
{
sqlinit = (*m_init) (NULL);
cout << dec << "m_init: " << m_init << endl;
}
else
{
cout << "fehler beim init" << endl;
}
//connect
m_connect = (BinaryFunction_c) GetProcAddress (hinstLib, "mysql_real_connect");
// Die Funktion aufrufen
if ( m_connect != NULL )
{
connid= (*m_connect) (sqlinit, "192.168.1.2", "cashbot", "eck1234", "cashbot", 3306, NULL, 0);
cout << "connid: " << connid << endl;
}
else
{
cout << "fehler beim connect" << endl;
}
// Die DLL-Datei wieder entladen
fFreeResult = FreeLibrary (hinstLib) ;
}
return 0;
}
OK, the problem was that the 64 bit win7 searches for the 64-bit version of the libmysql.dll in the SysWOW64 folder and this dll does not work with a 32 programm!