Hi,
I'm trying to create a program, that can handle song requests. Trough a webpage, someone can request a song, that song will be stored in a MySQL Database.
With my C++ program I want to select the requests, and if there're some requests, I want my program to play the song.
To communicate with winamp, I use this winamp plugin:
http://mysite.wanadoo-members.co.uk/...ock/Winamp.htm
I took al look at the C++ examples, and found out, that he uses #import to import the plugin DLL, and than create an instance to communicate with winamp.
So, I have this code now:
request.h
Code:
#import "c:\program files\winamp\plugins\gen_com.dll"
// Create prototype from Request class
class Request
{
public:
Request();
~Request();
protected:
// Mysql vars
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
// Winamp vars
WINAMPCOMLib::IApplicationPtr winamp;
// Functions
void handle_requests();
};
and
main.cpp
Code:
#include <mysql/mysql.h>
#include <cstdlib>
#include <iostream.h>
#include "request.h"
using namespace std;
Request::Request()
{
// Create winamp instance
winamp.CreateInstance(__uuidof(WINAMPCOMLib::Application));
// Connect to DB and, select DB
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, "localhost", "lucas", "charizard", "luckyradio"))
{
cout << "Failed to connect to database:\n" << mysql_error(&mysql);
exit(1);
}
}
Request::~Request()
{
mysql_close(db_conn);
}
Request::handle_requests()
{
cout << "Started Winamp Request Handler";
while(true)
{
if(!winamp->CurrentPos)
{
// Ok, end of a song, check for requests
if(mysql_query(&mysql, "SELECT * FROM e107_wa_requests ORDER BY request_id ASC LIMIT 1"))
{
result = mysql_store_result(&mysql);
while(row = mysql_fetch_row(result))
{
cout << "Requesting " << winamp->SongTitle(row[1]) << "...";
winamp->PlayListPos = row['request_playlist_nr'];
winamp->Play();
mysql_query(&mysql, sprintf("DELETE FROM e107_wa_requests WHERE request_id = %d", row[0]));
}
}
}
}
}
int main(int argc, char *argv[])
{
Request request;
request.handle_requests();
system("PAUSE");
return EXIT_SUCCESS;
}
But when I try to compile it, I get a lot of errors like
Stray '\14' in program
Stray '\31' in program
etc
and
[Warning] Null charactar(s) ignored
I use Dev-C++, newest version.
Does anyone know how to fix this?
And, another question:
Is it possible to use vars in strings?
like in PHP:
Code:
$name = "Peter";
echo "Hello ".$name;
Does this also work in C++?
Like this?
Code:
mysql_query(&mysql, "DELETE FROM e107_wa_requests WHERE request_id = ".row[0]);