1

[MSVS 2015]

I'm using MSVS 2015 and working on a C# windows phone 8.1 project through which I would like to run some C++ native code. Going off of this post here--How do I call C++/CLI from C#?--I created a C++ class library project. It's a simple, barebones thing for checking that step 0 works:

// CsCppTest.h

#pragma once

using namespace System;

namespace CsCppTest {

public ref class TestWrapper
{
    public:
        bool IsWorking()
        {
            return true;
        }
    };
}

I go into the project properties and under linker->input I set the Additional Dependencies property to 'Inherit from project' as per the instructions on the link I've mentioned above.

In my c# windows phone project, I haven't put in too much yet, just one line to the mainpage.xaml.cs:

    public MainPage()
    {
        this.InitializeComponent();

        this.DataContext = this;

        CsCppTest.TestWrapper miner = new CsCppTest.Testwrapper();

        this.NavigationCacheMode = NavigationCacheMode.Required;
    }

Ah, but this can't run yet. From mainpage, it doesn't have any idea what CsCppTest.TestWrapper means. I need to add a reference to my C++ project. So I right click on my C# project's references, and in reference manager I find an unchecked box next to my C++ project, I check it, hit OK and get:

Unable to add a reference to project 'CsCppTest'.

If there are pertinent details I've forgotten to include, please let me know.

What am I missing?

Community
  • 1
  • 1
MNagy
  • 423
  • 7
  • 20
  • 1
    A WinRT app (aka UWP, aka Store, aka Phone, aka Modern UI) cannot reference a C++/CLI library. WinRT targets .NETCore, it is missing crucial support for C++/CLI (AppDomains and module initializers). You'll have to create a C++/CX library instead and write pure native C++ code. – Hans Passant Jan 30 '17 at 22:10
  • Yes, really, windows phone. I am certain that both projects were created under version 4.5.2 of the .NET framework, but I may have to check to see if the same problem occurs with a different type of C# app (although, yes, I do in fact need this to work for windows phone). – MNagy Jan 30 '17 at 22:13
  • @HansPassant ah, that would explain it. You wouldn't know of a link similar to the one I posted that would give a decent beginning crash course for a C++/CX library in this context, would you? – MNagy Jan 30 '17 at 22:33

0 Answers0