Hello -
This is my first remotely useful win32 app and I'm having some issues...
The program simply connects to a MySQL database and displays the results in a ListBox. However, the function I am using to do this is crashing the program at run-time.
Code:
int DoMysqlStuff(HWND hwndDlg)
{
const char* host = "localhost";
const char* username = "xp";
const char* password = "*****";
const char* database = "nazgul_db";
MYSQL *conn;
conn = mysql_init(NULL);
if(mysql_real_connect(conn, host, username, password,
database, 0, NULL, 0)) {
const char *success = "Connected!";
SendDlgItemMessage(hwndDlg, IDC_LISTDB, LB_ADDSTRING, 0, (LPARAM) success);
}
// create vars to get a result and a row pointer from DB
MYSQL_RES *result_set;
MYSQL_ROW row;
unsigned int i;
mysql_query(conn, "SELECT id,name,level FROM guild_members");
result_set = mysql_store_result(conn);
if (!result_set) {
MessageBox(NULL, "Error storing result\n", "Error", MB_OK);
return -1;
}
// find out how many rows there will be
unsigned int numrows = mysql_num_rows(result_set);
while ((row = mysql_fetch_row(result_set)) != NULL) {
SendDlgItemMessage(hwndDlg, IDC_LISTDB, LB_ADDSTRING, 0, (LPARAM)(row[i] != NULL ? row[i] : "NULL"));
}
mysql_close(conn);
return 0;
}
I think the error is somewhere in the while() loop - I really don't know what it is though?
Any help would be appreciated,
Thank you
- rednax