cannot convert parameter 1 from 'char *' to 'long'

This is a discussion on cannot convert parameter 1 from 'char *' to 'long' within the C++ Programming forums, part of the General Programming Boards category; Ok, I switched to Visual C++ 2005 Express edition. I have this code: request.h Code: // Create prototype from Request ...

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

    cannot convert parameter 1 from 'char *' to 'long'

    Ok, I switched to Visual C++ 2005 Express edition.

    I have this code:

    request.h
    Code:
    // Create prototype from Request class
    class Request
    {
          public:
                 Request();
                 ~Request();
                 
                 // Main function
                 bool handle_requests();
                 
                 // MySQL Functions
                 bool connect_to_db();
                 
          protected:             
                 // Winamp vars
                 WINAMPCOMLib::IApplicationPtr winamp;
                 
                 // MySQL vars
                 MYSQL * mysql_conn;
                 MYSQL_RES * result;
                 MYSQL_ROW row;
                 
    };
    and main.cpp
    Code:
    #include <windows.h>
    #include <mysql.h>
    #include <iostream>
    #include <stdio.h>
    
    #import "c:\program files\winamp\plugins\gen_com.dll"
    #include "request.h"
    
    using namespace std;
    
    Request::Request()
    {
    	// Create winamp instance
    	Request::winamp.CreateInstance(__uuidof(WINAMPCOMLib::Application));			
    }
    Request::~Request()
    {
    	mysql_close(Request::mysql_conn);
    }
    
    bool Request::connect_to_db()
    {
    	mysql_init(Request::mysql_conn);
    	if(!mysql_real_connect(Request::mysql_conn, "localhost", "lucas", "***", "luckyradio", 0, NULL, 0))
    	{
    		cout << "Could not connect to database:\n" << mysql_error(Request::mysql_conn) << endl;
    		return false;
    	}
    	return true;
    }
    
    bool Request::handle_requests()
    {
    	cout << "Started Winamp Request Handler" << endl;
    	while(true)
    	{
    		if(!Request::winamp->CurrentPos)
    		{
    			if(!mysql_query(Request::mysql_conn, "SELECT * FROM e107_wa_request ORDER BY request_id ASC LIMIT 1"))
    			{
    				cout << "Error in selecting requests:\n" << mysql_error(Request::mysql_conn) << endl;
    				return false;
    			}
    			
    			result = mysql_use_result(Request::mysql_conn);
    			row = mysql_fetch_row(result);
    			
    			Request::winamp->put_PlayListPos(row[1]);
    			Request::winamp->Play();
    			
    			cout << "Requesting: " << Request::winamp->GetSongTitle(row[1]) << "..." << endl;  						
    		}
    	}
    	
    	return false;
    }
    
    int main()
    {
    	Request request;
    	if(request.connect_to_db())
    	{
    		while(request.handle_requests())
    		{
    			// do nothing
    		}
    	
    		cin.get();
    	}
    	
    	return 1;
    }
    But I Get this error:
    ------ Rebuild All started: Project: Requester, Configuration: Debug Win32 ------
    Deleting intermediate and output files for project 'Requester', configuration 'Debug|Win32'
    Compiling...
    main.cpp
    .\main.cpp(48) : error C2664: 'WINAMPCOMLib::IApplication:ut_PlayListPos' : cannot convert parameter 1 from 'char *' to 'long'
    There is no context in which this conversion is possible
    .\main.cpp(51) : error C2664: 'WINAMPCOMLib::IApplication::GetSongTitle' : cannot convert parameter 1 from 'char *' to 'long'
    There is no context in which this conversion is possible
    Build log was saved at "file://c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Requester\Requester\Debug\BuildLog.h tm"
    Requester - 2 error(s), 0 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
    Does anyone know how I can fix this?

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    It appears that your functions are looking for long and not char*. If this a "work-around" for passing a pointer to the function then you will have to use reinterpret_cast<long>. I can only gues the function internal will cast it back to the pointer in order to use it.

  3. #3
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39
    something like this?

    Code:
    Request::winamp->put_PlayListPos(<long>row[1]);
    ?

  4. #4
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by MrLucky
    something like this?

    Code:
    Request::winamp->put_PlayListPos(<long>row[1]);
    ?
    You forgot the reinterpret_cast part. Like this.

    Code:
    Request::winamp->put_PlayListPos(reinterpret_cast<long>row[1]);
    This will work as far as solving the "type" conflict, whether or not it works logical I do not know without knowing the underlying code.

  5. #5
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39
    I've got this now:

    Code:
    bool Request::handle_requests()
    {
    	cout << "Started Winamp Request Handler" << endl;
    	while(true)
    	{
    		if(!Request::winamp->CurrentPos)
    		{
    			if(!mysql_query(Request::mysql_conn, "SELECT * FROM e107_wa_request ORDER BY request_id ASC LIMIT 1"))
    			{
    				cout << "Error in selecting requests:\n" << mysql_error(Request::mysql_conn) << endl;
    				return false;
    			}
    			
    			result = mysql_use_result(Request::mysql_conn);
    			row = mysql_fetch_row(result);
    			
    			long playlist_pos = reinterpret_cast<long>(row[1]);
    			
    			Request::winamp->put_PlayListPos(playlist_pos);
    			Request::winamp->Play();
    			
    			cout << "Requesting: " << Request::winamp->GetSongTitle(playlist_pos) << "..." << endl;  						
    		}
    	}
    	
    	return false;
    }
    and this works

    But now, I get some other errors..

    ------ Build started: Project: Requester, Configuration: Debug Win32 ------
    Compiling...
    main.cpp
    Linking...
    main.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function "public: __thiscall Request::~Request(void)" (??1Request@@QAE@XZ)
    main.obj : error LNK2019: unresolved external symbol _mysql_error@4 referenced in function "public: bool __thiscall Request::connect_to_db(void)" (?connect_to_db@Request@@QAE_NXZ)
    main.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function "public: bool __thiscall Request::connect_to_db(void)" (?connect_to_db@Request@@QAE_NXZ)
    main.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: bool __thiscall Request::connect_to_db(void)" (?connect_to_db@Request@@QAE_NXZ)
    main.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function "public: bool __thiscall Request::handle_requests(void)" (?handle_requests@Request@@QAE_NXZ)
    main.obj : error LNK2019: unresolved external symbol _mysql_use_result@4 referenced in function "public: bool __thiscall Request::handle_requests(void)" (?handle_requests@Request@@QAE_NXZ)
    main.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: bool __thiscall Request::handle_requests(void)" (?handle_requests@Request@@QAE_NXZ)
    C:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Requester\Debug\Requester.exe : fatal error LNK1120: 7 unresolved externals
    Build log was saved at "file://c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Requester\Requester\Debug\BuildLog.h tm"
    Requester - 8 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    I think I know how to fix this problem, just add the libmysql linker to my project. But does anyone know where I can add linkers to my project in Visual C++ 2005?
    Last edited by MrLucky; 01-24-2006 at 12:25 PM.

  6. #6
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    These are linker errors, have you inluded the mysql libraries in your project? With MSVC there are 2 ways you could do this. Easiest but non-portable is put this in your file: pragma comment (lib, "name_of_your_library"). The second way is to put it in the project linker properties in the "include additional libraries" option ( do it for both debug and release)

  7. #7
    C++ Programmer
    Join Date
    Aug 2005
    Posts
    39
    something like this?

    Code:
    #pragma "c:\mysql\lib\libmysqlclient.lib"
    ?

    Edit
    Already got it..
    Last edited by MrLucky; 01-25-2006 at 11:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 08:36 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 10:22 AM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 09:21 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM

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