1

I'm trying to use the PJSIP lirbrary in a Visual C++ project with CLR support. After googling for hours and hours and trying I got no clue, why my project will not compile. I will tell you, step by step what I've done so far and I hope you guys can tell me, whats wrong with my configuration.

  1. I checked out from the PJSIP repository
  2. I opened the solution in Visual Studio 2013 (Express)
  3. Visual Studio migrated the projects, after the migration was done, I was able to compile the PJSIP project without further problems, the .LIB file was created, PJSIP does not use CLR
  4. Afterwards, I created a new Visual C++ project (with CLR) and tried to access the PJSIP library. Compiling was successful, but linking gave many errors (errors like: call to external reference not possible...)
  5. Then, Google meant, it is not possible to call methods of a static library from a CLR supported application. My fault that I thought it would be that easy :-(
  6. However, I searched again and then I found the possibility to "wrap" the calls to PJSIP with a CLR wrapper class. This wrapper class is embedded in a DLL. This DLL I can use in my Visual C++ project (here a step-by-step guide, I did #3: http://social.msdn.microsoft.com/Forums/vstudio/en-US/299da822-5539-4e5b-9ba7-b614e564c9f4/presenting-a-c-library-lib-for-use-in-c-project?forum=vcgeneral)

I can create the wrapper class, it compiles nicely, the DLL is created. I can also reference to this DLL from my Visual C++ project, but if I try to access the methods, Visual Studio compiler says, it does not kwno the methods.

On stackoverflow are many questions regarding this topic, however, no answer solved my problem (i.e. How to access class in C++/CLI from C#?)

Here is some code, I hope this makes my point clearer:

#include <pjlib.h>
#include <pjlib-util.h>
#include <pjnath.h>
#include <pjsip.h>
#include <pjsip_ua.h>
#include <pjsip_simple.h>
#include <pjsua-lib/pjsua.h>
#include <pjmedia.h>
#include <pjmedia-codec.h>

#pragma once

using namespace System;

namespace PJSIPCLRWrapper {

public ref class pjsipWrapper
{
    static int pjsipInit()
    {
    pj_status_t status;

    /* Must init PJLIB first: */
    // pj_init is a function from the PJSIP lib
    status = pj_init();

    return (int)status;
    }
}

#include "stdafx.h"

using namespace System;


int main(array<System::String ^> ^args)
{   
    // this line procduces error C2882: 'PJSIPCLRWrapper': illegal use of namespace identifier in expression
    PJSIPCLRWrapper.pjsipWrapper.pjsipInit();
    return 0;
}

I searched the whole day the internet how to fix the problem. I got many solutions however no solution provieded solved my problem. I'm afraid, it is not possible or I make a terrible mistake.

I appreciate your help! regards Lukas

Community
  • 1
  • 1

2 Answers2

1

I could not find any solution for my problem, except, that I switched to Visual C++ without CLR support for my program. Here I can use the complete PJSIP library without a wrapper. Although, I can not use the advantages of CLR :-/

Best regards, Lukas

0

To call a static function in C++/CLI, it should be:

PJSIPCLRWrapper::pjsipWrapper::pjsipInit();
Matt
  • 6,010
  • 25
  • 36
  • thank you @matt. i changed the erroneous line to PJSIPCLRWrapper::pjsipWrapper::pjsipInit(); however, now error C3767 ""PJSIPCLRWrapper::pjsipWrapper::pjsipInit": candidate function(s) not accessible" appears. but the method pjsipInit() exists according to the header file. i tried to remove the "static" keyword, lead to the same problem. – Lukas Tröllinger Aug 17 '14 at 16:49