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. C#
  4. C# app using a C++ dll

C# app using a C++ dll

Scheduled Pinned Locked Moved C#
questioncsharpc++
6 Posts 4 Posters 0 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.
  • L Offline
    L Offline
    LCI
    wrote on last edited by
    #1

    I have a C++ dll. I would like to use a C# to access two methods within that dll. What is the best way to do this. I cannot seem to find much information on getting the C# app to talk to the C++ dll. Is this possible? If so, how? Thanks, cw

    G 1 Reply Last reply
    0
    • L LCI

      I have a C++ dll. I would like to use a C# to access two methods within that dll. What is the best way to do this. I cannot seem to find much information on getting the C# app to talk to the C++ dll. Is this possible? If so, how? Thanks, cw

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      P/Invoke[^] is your friend

      #region signature my articles #endregion

      L 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        P/Invoke[^] is your friend

        #region signature my articles #endregion

        L Offline
        L Offline
        LCI
        wrote on last edited by
        #3

        I tried placing [DllImport("My.dll")] static extern int MakeQUERY(string strTag) ; Inside my C# class. The call MakeQUERY is in my C++ dll. But when i try to build this, i get an error: "The type or namespace name "DllImport" could not be found(are you missing a using directive or an assembly reference)

        L M 2 Replies Last reply
        0
        • L LCI

          I tried placing [DllImport("My.dll")] static extern int MakeQUERY(string strTag) ; Inside my C# class. The call MakeQUERY is in my C++ dll. But when i try to build this, i get an error: "The type or namespace name "DllImport" could not be found(are you missing a using directive or an assembly reference)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Yeah, that happens a lot. It typically means you are missing a using directive or an assembly reference (and probably both). Have a look at some other program that tries to do what you are trying, i.e. search CodeProject (or Google) for "DllImport" :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


          1 Reply Last reply
          0
          • L LCI

            I tried placing [DllImport("My.dll")] static extern int MakeQUERY(string strTag) ; Inside my C# class. The call MakeQUERY is in my C++ dll. But when i try to build this, i get an error: "The type or namespace name "DllImport" could not be found(are you missing a using directive or an assembly reference)

            M Offline
            M Offline
            Mohib Sheth
            wrote on last edited by
            #5

            You will need to add this one line to able to use DllImport. using System.Runtime.InteropServices; Cheers.

            ------------------------------------------------------------------ Life would have been much easier if I had the source-code!!

            L 1 Reply Last reply
            0
            • M Mohib Sheth

              You will need to add this one line to able to use DllImport. using System.Runtime.InteropServices; Cheers.

              ------------------------------------------------------------------ Life would have been much easier if I had the source-code!!

              L Offline
              L Offline
              LCI
              wrote on last edited by
              #6

              Thanks that got me further. Now it is throwing a System.EntryPointNotFound error. My dll looks like this. #include "stdafx.h" #include "Mydll.h" #include #include #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } DLL_API MakeQUERY(LPCSTR strTH, LPCSTR strEH, LPCSTR strSenderID, std::string strPath) { } I added this to my C# declaration [DllImport("LCIBroker.dll", EntryPoint = "DllMain")] But it still cannot find the EntryPoint. Is there something that i am missing?

              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