Problem with #import

This is a discussion on Problem with #import within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm trying to create a program, that can handle song requests. Trough a webpage, someone can request a song, ...

  1. #1
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39

    Problem with #import

    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]);
    Last edited by MrLucky; 01-21-2006 at 03:56 AM.

  2. #2
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39
    Nobody?

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    So much for MrLucky.

    And, another question:

    Is it possible to use vars in strings?
    like in PHP:

    Code:
    $name = "Peter";
    echo "Hello ".$name;
    For C++ strings, you can use the + operator:
    Code:
    string name = "Peter";
    name = name + " Lastname";
    For C strings (character arrays), use strcat().
    Code:
    #include <cstring>
    char name[100] = "Peter";
    
    strcat(name, " Lastname");
    And now for your first question. Evidently your compiler doesn't like this:
    Code:
    #import "c:\program files\winamp\plugins\gen_com.dll"
    It seems to be functioning in the same way as #include. I would suggest linking your programs to the DLL instead. Create a project (if you haven't already) and add the DLL to the libraries to link to.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39
    Ah, thnx dwks!

    I would try it

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    #import is a VC++-specific feature. You can't use it in Dev-C++. What it does is read COM type information from the DLL and automatically create a wrapper class. Without this feature, your code will be a lot more complicated.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39
    Hmm, ok. Is there any other way to create a COM object in C++?

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Sure. Call CoInitialize, CoCreateInstance, QueryInterface, and all the other ridiculously complicated COM stuff.

    I suggest you search for tutorials. It's mostly boilerplate code, so you don't even really need to understand it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If the object supports scripting (most do), you can use DispHelper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. File import opinion.
    By Kennedy in forum Tech Board
    Replies: 2
    Last Post: 09-22-2006, 05:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21