Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Error: cannot convert from (__clrcall *) to (__cdecl *) (http://www.go4expert.com/forums/error-convert-clrcall-cdecl-t23207/)

sujw 5Sep2010 16:54

Error: cannot convert from (__clrcall *) to (__cdecl *)
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 *)

Please help. Thanks.

Following is the code that is causing the error:


#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
//TODO: Add the constructor code here
/// <summary>
/// Clean up any resources being used.
/// </summary>
if (components)
delete components;
private: System::Windows::Forms::Button^ button1;
/// <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());
// 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->Name = L"Form1";
this->Text = L"Form1";
#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;
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;
cfg.port = 5060;
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);


status = pjsua_start();

pjsua_acc_config cfg;

cfg.id = pj_str("sip:abc@");
cfg.reg_uri = pj_str("sip:");
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);

xpi0t0s 6Sep2010 13:28

Re: Error: cannot convert from (__clrcall *) to (__cdecl *)
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.

xpi0t0s 6Sep2010 13:31

Re: Error: cannot convert from (__clrcall *) to (__cdecl *)
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.

All times are GMT +5.5. The time now is 12:10.