c# - How to import C++ dll in Windows Phone Project -


i have created dll file in c++. want import in windows phone project. have followed number of instructions different sources, when run code getting following error:

attempt access method failed: rough.mainpage.add(system.int32, system.int32).

my windows phone c# code here:

*//here c# code windows phone namespace testrsa {     using system.runtime.interopservices;      public partial class mainpage : phoneapplicationpage     {         [dllimport("myfunc.dll", entrypoint = "add", callingconvention =          callingconvention.stdcall)]         static extern int add(int a, int b);          // constructor         public mainpage()         {             initializecomponent();             int result = add(27, 28);             system.diagnostics.debug.writeline(7);         }     } } 

my dll .h file here:

#include "stdafx.h" #include "myfunc.h" #include <stdexcept>  using namespace std;   double __stdcall add(double a, double b) {     return + b;  } 

my dll .cpp file here: #include "stdafx.h" #include "myfunc.h" #include

using namespace std; double __stdcall add(double a, double b) {     return + b;  } 

to import make use of c++ c# project have make visible managed code. so, should create new 'windows phone runetime' component, under visual c++ section in new project menu. can name project "dll" example.

once project created can modify source have looks this.

dll.cpp :

#include "dll.h"  namespace ns {      double cpp_class::cppadd(double a, double b)     {         return + b;     } } 

dll.h :

#pragma once  namespace ns {     public ref class cpp_class sealed /* makes class visible managed code */     {         public:             static double cppadd(double a, double b);     }; } 

compile verify didn't wrong. once done, create new windows phone app project (under visual c# in new project menu. right click solution name , select 'add' > 'add existing project', select dll project. once did this, right click windows phone app project, select 'add reference', under 'solution' tab, you'll see dll project.

if did correctly, can use native code inside c# portion of windows phone app "using" :

using dll;  [...] ns.cpp_class.add(1,3); 

remember won't able use component if didn't add reference.

i hope helps !


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -