locked
Adding a C++ dll refrence to a C# project

    Question

  • I have a .dll written in c++ and I want to add it's reference into my c# project: when I add it, an error occurs I have acttached the snapshot  of the error here.

    Sunday, March 16, 2014 7:58 AM

Answers

  • The error you get exactly explains the reason. Basically .NET Core is a subset of  .NET Framework which is allowed to be used in Windows Store Apps and your C++ dll must be targeting all of .NET Framework. Do not think of it as a interoperability issue between C++ and C#, this will be the case if you have a regular C# dll.


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Sunday, March 16, 2014 9:43 AM
  • As the error suggests, you have a DLL compiled for the full .Net Framework and not for the .Met Core Framework supported for Windows Store apps. See .NET for Windows Store apps overviewinvoke if the use API allowed for Windows Store apps (See Win32 and COM for Windows Store apps) or you can use Windows Runtime Components written in C++.

    A quick search on FFMPEG WinRT found a codeproject project that claims to support FFMPEG in Windows Store apps, so you might want to try that.

    --Rob

    Sunday, March 16, 2014 6:02 PM
    Owner

All replies

  • The error you get exactly explains the reason. Basically .NET Core is a subset of  .NET Framework which is allowed to be used in Windows Store Apps and your C++ dll must be targeting all of .NET Framework. Do not think of it as a interoperability issue between C++ and C#, this will be the case if you have a regular C# dll.


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Sunday, March 16, 2014 9:43 AM
  • As the error suggests, you have a DLL compiled for the full .Net Framework and not for the .Met Core Framework supported for Windows Store apps. See .NET for Windows Store apps overviewinvoke if the use API allowed for Windows Store apps (See Win32 and COM for Windows Store apps) or you can use Windows Runtime Components written in C++.

    A quick search on FFMPEG WinRT found a codeproject project that claims to support FFMPEG in Windows Store apps, so you might want to try that.

    --Rob

    Sunday, March 16, 2014 6:02 PM
    Owner
  • I have tried in this way as well

    Created a C++ dll for windows store apps and then I tried to add in my C# project (for windows 8) still I get the same error...

    Friday, March 21, 2014 10:20 AM
  • Add reference is for components, not for standard C++ DLL. For a normal DLL add the file to the project and mark it as content to be included in the app package. You can then pinvoke it from your C# code.
    Friday, March 21, 2014 3:08 PM
    Owner
  • How do i create object of a class using pinvoke? Can I do that? After creating object of a class function calling is same as it is in managed code?
    Friday, March 21, 2014 10:01 PM
  • No, you cannot call straight C++ classes directly from C#. You can pinvoke functions, not classes.

    The most straightforward way is to create a Windows Runtime Component and create your class as a runtime class. See Creating Windows Runtime components

    Friday, March 21, 2014 10:13 PM
    Owner