Error: cannot convert from (__clrcall *) to (__cdecl *)

Discussion in 'C' started by sujw, Sep 5, 2010.

  1. sujw

    sujw New Member

    Joined:
    Sep 5, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am compiling in Visual C++ 2005 Express Edition.


    I am getting the following error:

    error C2440: '=' : cannot convert from 'void (__clrcall sept05::Form1::* )(pjsua_call_id)' to 'void (__cdecl *)
    (pjsua_call_id)'


    Please help. Thanks.


    Following is the code that is causing the error:



    Code:
    #pragma once
     
    #include "pjsua-lib/pjsua.h"
     
    namespace sept05 {
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    /// <summary>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    /// 'Resource File Name' property for the managed resource compiler tool
    /// associated with all .resx files this class depends on. Otherwise,
    /// the designers will not be able to interact properly with localized
    /// resources associated with this form.
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    Form1(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }
    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::Button^ button1;
    protected: 
    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;
    #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
    this->button1 = (gcnew System::Windows::Forms::Button());
    this->SuspendLayout();
    // 
    // button1
    // 
    this->button1->Location = System::Drawing::Point(173, 124);
    this->button1->Name = L"button1";
    this->button1->Size = System::Drawing::Size(75, 23);
    this->button1->TabIndex = 0;
    this->button1->Text = L"button1";
    this->button1->UseVisualStyleBackColor = true;
    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    // 
    // Form1
    // 
    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(284, 262);
    this->Controls->Add(this->button1);
    this->Name = L"Form1";
    this->Text = L"Form1";
    this->ResumeLayout(false);
    }
    #pragma endregion
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    
    pj_status_t status;
    pjsua_acc_id acc_id;
     
    status = pjsua_create();
    {
    pjsua_config cfg;
    pjsua_config_default(&cfg);
    cfg.cb.on_call_media_state = &on_call_media_state;    //this line is creating error
     
    status = pjsua_init(&cfg, NULL, NULL);
    }
    
    {
    pjsua_transport_config cfg;
    pjsua_transport_config_default(&cfg);
    cfg.port = 5060;
    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
    
    }
    
    status = pjsua_start();
    
    {
    pjsua_acc_config cfg;
    
    pjsua_acc_config_default(&cfg);
    cfg.id = pj_str("sip:abc@1.1.1.1");
    cfg.reg_uri = pj_str("sip:1.1.1.1");
    cfg.cred_count = 1;
    cfg.cred_info[0].realm = pj_str("aaa");
    cfg.cred_info[0].scheme = pj_str("digest");
    
    cfg.cred_info[0].username = pj_str("abc");
    cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
    cfg.cred_info[0].data = pj_str("abc");
     
    
    status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
     
     
    
    }
     
     
     
    }
    
    // Callback called by the library when call's media state has changed 
    private: static void on_call_media_state(pjsua_call_id call_id)
    {
    pjsua_call_info ci;
    
    pjsua_call_get_info(call_id, &ci);
    if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
    // When media is active, connect call to sound device.
    pjsua_conf_connect(ci.conf_slot, 0);
    pjsua_conf_connect(0, ci.conf_slot);
    }
    }
     
    };
    }
     
    Last edited by a moderator: Sep 5, 2010
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Is cfg.cb of type 'void (__clrcall sept05::Form1::* )(pjsua_call_id)'? I can't tell, because pjsua_config is defined in code you haven't posted. If not, then there's the reason for the error, and you need to change the type or do a cast.

    BTW, if you use code tags when you post, it retains formatting. The above is pretty unreadable as all the indenting has been removed.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Or use a compile flag that tells the compiler to stop being so whiny about a simple function address assignment. Or tell us you weren't trying to assign the address of the function to cfg.cb.on_call_media_state but were instead trying to call the function and assign the return value :)

    Oh and I should have asked for the type of cfg.cb.on_call_media_state, not cfg.cb.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice