Currently I need to call a C# function from C++ code on windows phone, I read a lot about P/Invoke, this thread might be a duplicate.....
But so far I didn't find a "complete" thread includes projects and hook up teaches me how to do this Also there are tons of terminology confused me. So I have to create this thread:
Q1. If I don't want to use COM, the tech I should use is called ? This tech requires me to create a C# dll, then I can call the function in the C# dll from C++ code, right?
--------On C# side:
Q2. Project wise I should place the function I want to call from C++ code in a C# DLL project. So the type of the project I created is Is there anything else I need to manually setup on project side?
Q3. In the *.cs file, Use deligate, all the reference use deligate. But some of reference use
[DllExport( "blah.dll", CallingConvention=CallingConvention.StdCall) ]
Some of them not. Which confuses me. Is Dllexport must required for the dll function in *.cs?
--------On C++ side:
Q4. Project setting wise, People say, I should use C++/CLI(Common Language Infrastructure) What confused me here is, is (CLI) a setting in project? How do I know my C++ project is CLI or not? or how do I set that? How do I know my C++ project is Managed or not? or how do I set that?
Actually I new/delete in the C++, so it should be machine code(unmanaged) But does the C++ project that calls C# function has to be managed? And does managed/unmanaged has something to do with CLI?
--------On both C#/C++ project side:
Q5 None of the tutorial tells me how to hook up the projects!
I did this by adding the to the like this: Common Properties->Add New Reference
But when try to call the C# function from C++, It tells me error, unsolved external. I tried put the function in a C# name space, then in C++, I write:
using namespace MyCSharpNamespace;
It gives me an error:
error C2871: 'MyCSharpNamespace' : a namespace with this name does not exist
If it's a C++ dll, I just need to include the C++ header file, then it's done. But what do I do with a *.cs file?
I'll really appreciate the answer from you guys.