简体   繁体   中英

using C# lib from native C++ program

I try to use a C# lib (actually referenced the whole project other than the dll) in a native C++ program.

Basically I followed the example here: http://harinadha.wordpress.com/2011/10/17/ximucppapi/

I create an empty sln in VS, add the C# program in this sln. Then create a wrapper C++ program, which referenced the C# project, and in the header file it`s using the C# namespace:

#include <string>

using namespace CsharpNamespace; //this is the C# namespace, has all the classes/ functions I need.
using namespace std;

namespace Wrapper
{
    public ref class CsharpClassWrapper
    {
        public:
        ReaderWrapperClass(){}

        static AllData ^AllDataWrapper; //the AllData class is the C# class
        static unsigned int ID;
        void Initial(string s);
    };
}

Now the problem is that VS2012 says that it cannot find the namespace. Although it can find the AllData class and everything related to it ( functions, members etc), and the class name is highlighted like it knows this class; and when I remove the using statement, it cannot find it anymore and will throw an error saying the class is not defined.

Any idea what might be wrong? Any input is greatly appreciated!

Update:

I have a third project, it will use the wrapper project, and call the wrapper function. If I only compile the wrapper project and the C# project, it works fine, no error is thrown. But if I try to compile the third one (main project), it will have the above warning.

I finally find the answer following the instruction in the video: http://msdn.microsoft.com/en-us/vstudio/bb892741

He says that in C++ project, you don't need to enable "Common Language Runtime Support (/clr)", that`s not correct, you still needs to use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM