I don't have much experience in C++. I am using Visual Studio 2012 to build.
I have:
- A solution with:
- Static Library in C++ (not in C++/CLI).
- C++ Tests project (here i am testing all the code from the C++ Static library)
- Wrapper Project C++/CLI
- Another solution with:
- C# Test Project
I want to build the first solution and then use the resulting dlls in the C# Unit tests. Later on the C++/CLI will be used in several projects, so I am creating Tests to verify the functionality.
When I created the C++/CLI projected, It created Class1 by default. I didn't delete this class yet, but I created a wrapper for one of the C++ Classes.
When I add this dll to the C# project, the Class1 is visible (I even added a test method and it works), but I can access the Wrapper Class I created.
My C++/CLI project name is:
- MyNamespace.SubNamespace.Managed.MyProject
The Class1 Code (C++/CLI)
#pragma once
using namespace System;
namespace MyNamespaceSubNamespaceManagedMyProject
{
public ref class Class1
{
public:
//I used this method to see if the values were going back and forth, and they do
int TestMethod(int value){return value;}
};
}
My Wrapper Class.h Code (C++/CLI)
#pragma once
#include "..\C++ProjectFolderPath\MyCPPClass.h"
namespace MyNamespace { namespace SubNamespace { namespace ManagedTest {
ref class MyManagedWrapper
{
private:
MyNamespace::SubNamespace::UnmanagedTest::MyCPPClass *myInstance;
public:
MyManagedWrapper(double value1, System::String ^text1,
System::String ^text2, array<System::Double>^ double1,
array<System::Double>^ double2, array<System::Double>^ double3,
array<System::Double>^ double4);
~MyManagedWrapper();
};
}}}
My C# Test
[TestClass]
public class TEMServiceCppTest
{
[TestMethod]
public void TestMethod1()
{
var test = new Class1();
Assert.AreEqual(3, test.TestMethod(3));
}
}
Class1 works just fine, but I try to do new MyManagedWrapper() and It doesn't work. I tried using the fullnamespace too but it is like the class and the namespace doesn't exist.
I used this page as a reference to create my code. Why would the Class1 class be accessible and not the class I am created? I tried to find if there was some special place I had to register the Class1 or it's namespace, but I couldnt find any.
I don't know how to make my MyManagedWrapper class visible my C# code.
(If you need more detail, let me know and I will add it)