Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to use non .NET DLLs in .NET environment?

How to use non .NET DLLs in .NET environment?

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++asp-netvisual-studio
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Khang Nguyen
    wrote on last edited by
    #1

    Happy Friday! Gurus, I am trying to use the logics from Intel OpenCV DLLs, which were originally compiled by MSVC++ 6. From C# or ASP.NET Apps, when I was trying to add reference to these DLLs (i.e. cv096.dll or cxcore096.dll), I got this error: “A reference to ‘D:\Programs\OpenCV\bin\cv096.dll’ could not be added. This is not a valid assembly or COM component. Only assemblies with extension ‘dll’ and COM components can be referenced. Please make sure it is a valid assembly or COM component.” Note: The source code of Intel OpenCV DLLs is open source. I can open this source code project in either MSVC++ 6 or VS.NET 2003. Question: How can I use these DLLs in .NET environment, preferably in ASP.NET and C# projects? Thanks with a million Khang :)

    U P 2 Replies Last reply
    0
    • K Khang Nguyen

      Happy Friday! Gurus, I am trying to use the logics from Intel OpenCV DLLs, which were originally compiled by MSVC++ 6. From C# or ASP.NET Apps, when I was trying to add reference to these DLLs (i.e. cv096.dll or cxcore096.dll), I got this error: “A reference to ‘D:\Programs\OpenCV\bin\cv096.dll’ could not be added. This is not a valid assembly or COM component. Only assemblies with extension ‘dll’ and COM components can be referenced. Please make sure it is a valid assembly or COM component.” Note: The source code of Intel OpenCV DLLs is open source. I can open this source code project in either MSVC++ 6 or VS.NET 2003. Question: How can I use these DLLs in .NET environment, preferably in ASP.NET and C# projects? Thanks with a million Khang :)

      U Offline
      U Offline
      ursus zeta
      wrote on last edited by
      #2

      I'm not familiar with the Intel OpenCV DLLs, but if they are not .NET assemblies (which they aren't if compiled with VC++ 6), you actually must use the Interop to incorporate them into a managed application. I use Visual C++ .NET, but, I think the syntax is the same (or very similar). The idea is to import the function from the DLL using the [DllImport] attribute, which resides in the System.Runtime.InteropServices. Read this stuff: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]

      1 Reply Last reply
      0
      • K Khang Nguyen

        Happy Friday! Gurus, I am trying to use the logics from Intel OpenCV DLLs, which were originally compiled by MSVC++ 6. From C# or ASP.NET Apps, when I was trying to add reference to these DLLs (i.e. cv096.dll or cxcore096.dll), I got this error: “A reference to ‘D:\Programs\OpenCV\bin\cv096.dll’ could not be added. This is not a valid assembly or COM component. Only assemblies with extension ‘dll’ and COM components can be referenced. Please make sure it is a valid assembly or COM component.” Note: The source code of Intel OpenCV DLLs is open source. I can open this source code project in either MSVC++ 6 or VS.NET 2003. Question: How can I use these DLLs in .NET environment, preferably in ASP.NET and C# projects? Thanks with a million Khang :)

        P Offline
        P Offline
        Paul Ingles
        wrote on last edited by
        #3

        As mentioned in the previous post, you can't add a reference to the DLL since it's neither a .NET assembly, nor exposing COM interfaces -- when you add a reference to a COM DLL VS.NET just generates a .NET P/Invoke wrapper around it so you can use it without declaring things yourself. Again, you can either go down the route of writing DllImport & P/Invoke stubs (although if you're using reasonably complicated data structures this can be time consuming unless someone else has already converted them). Alternatively, you can use the (rather cool in my opinion) It Just Works functionality within MC++. Effectively you write a .NET wrapper around the functionality exposed by the Intel libraries by linking etc. as you would with MSVC++6. Now, I'm a little rusty on this, I've not done any MC++/interop code for a good while now, but it should be relatively straightforward. Effectively you compile your assembly with the /CLR compiler switch, this in turn generates managed code, including the P/Invoke code that would otherwise be up to you to write in C#. Of course, you'll need to make sure you link with the libraries, and include the headers. If you get stuck with that I'm sure people will be able to give you more detailed instructions. -- Paul MS Messenger: paul -at- oobaloo-co-uk

        K 1 Reply Last reply
        0
        • P Paul Ingles

          As mentioned in the previous post, you can't add a reference to the DLL since it's neither a .NET assembly, nor exposing COM interfaces -- when you add a reference to a COM DLL VS.NET just generates a .NET P/Invoke wrapper around it so you can use it without declaring things yourself. Again, you can either go down the route of writing DllImport & P/Invoke stubs (although if you're using reasonably complicated data structures this can be time consuming unless someone else has already converted them). Alternatively, you can use the (rather cool in my opinion) It Just Works functionality within MC++. Effectively you write a .NET wrapper around the functionality exposed by the Intel libraries by linking etc. as you would with MSVC++6. Now, I'm a little rusty on this, I've not done any MC++/interop code for a good while now, but it should be relatively straightforward. Effectively you compile your assembly with the /CLR compiler switch, this in turn generates managed code, including the P/Invoke code that would otherwise be up to you to write in C#. Of course, you'll need to make sure you link with the libraries, and include the headers. If you get stuck with that I'm sure people will be able to give you more detailed instructions. -- Paul MS Messenger: paul -at- oobaloo-co-uk

          K Offline
          K Offline
          Khang Nguyen
          wrote on last edited by
          #4

          Paul, thank you so much for your very descriptive and helpful insights. I really appreciate your spent time for thinking and writing it up. Wish you a beautiful Spring season. Again, Thanks Khang

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups