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 / C++ / MFC
  4. problem using VC++ DLL in VC#

problem using VC++ DLL in VC#

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++helpquestionvisual-studio
4 Posts 2 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.
  • S Offline
    S Offline
    saania khan
    wrote on last edited by
    #1

    Hi, I am trying to create and then use a VC++ DLL in C#. I created the DLL in Visual Studio 2005. I just built the dll without adding any function of mine to it. That is, it is a dll that exports symbols and has the following pre-defined export symbols/functions. // This is an example of an exported variable TEST_API int ntest=0; // This is an example of an exported function. TEST_API int fntest(void) { return 42; } where, #define TEST_API __declspec(dllexport) Then I created a simple VC# empty project ( in Visual Studio 2005) and added the class "test" to it. When I add the VC++ dll as a reference I get this error .... "A reference to "../test.dll" could not be added. Please make sure that the file is accessible, that it is a valid assembly or COM component". Even though I dont think it needs a conversion from COM to COM+, I even tried doing "tlbimp". I went to the command prompt for Visual Studio 2005, followed the path to where my dll resides and used the tlbimp command. But I got the error that test.dll is not a valid type library. Someone told me that I need to register the dll using regsrv32 and it would show in my COM list when I am adding it as a reference. But that didnt work either. When I run the regsrv32, I get the error message as "..\test.dll was loaded, but the DLLRegisterServer entry point was not found" ... I just want to know that what is it that I am doing wrong? Is there something else that I should be doing ? All I did for creating the test.dll was ...... I went to File->New->Project. Under Visual C++ I selected Win32 and then Win32 Project. In the Application settings I selected the DLL and then checked the export symbol box. I simply built the project and was trying to use it. Thanks for your time. Saania

    C 1 Reply Last reply
    0
    • S saania khan

      Hi, I am trying to create and then use a VC++ DLL in C#. I created the DLL in Visual Studio 2005. I just built the dll without adding any function of mine to it. That is, it is a dll that exports symbols and has the following pre-defined export symbols/functions. // This is an example of an exported variable TEST_API int ntest=0; // This is an example of an exported function. TEST_API int fntest(void) { return 42; } where, #define TEST_API __declspec(dllexport) Then I created a simple VC# empty project ( in Visual Studio 2005) and added the class "test" to it. When I add the VC++ dll as a reference I get this error .... "A reference to "../test.dll" could not be added. Please make sure that the file is accessible, that it is a valid assembly or COM component". Even though I dont think it needs a conversion from COM to COM+, I even tried doing "tlbimp". I went to the command prompt for Visual Studio 2005, followed the path to where my dll resides and used the tlbimp command. But I got the error that test.dll is not a valid type library. Someone told me that I need to register the dll using regsrv32 and it would show in my COM list when I am adding it as a reference. But that didnt work either. When I run the regsrv32, I get the error message as "..\test.dll was loaded, but the DLLRegisterServer entry point was not found" ... I just want to know that what is it that I am doing wrong? Is there something else that I should be doing ? All I did for creating the test.dll was ...... I went to File->New->Project. Under Visual C++ I selected Win32 and then Win32 Project. In the Application settings I selected the DLL and then checked the export symbol box. I simply built the project and was trying to use it. Thanks for your time. Saania

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      OK, you're a bit lost here. You are not creating a COM dll, let alone COM+. You're writing a plain, vanilla, dll. You need to use p/invoke to call methods on this dll. If you're writing it from scratch, I'd be more inclined to use C++/CLI to write a DLL that IS an assembly and which can be imported.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      S 1 Reply Last reply
      0
      • C Christian Graus

        OK, you're a bit lost here. You are not creating a COM dll, let alone COM+. You're writing a plain, vanilla, dll. You need to use p/invoke to call methods on this dll. If you're writing it from scratch, I'd be more inclined to use C++/CLI to write a DLL that IS an assembly and which can be imported.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S Offline
        S Offline
        saania khan
        wrote on last edited by
        #3

        Thanks for the reply, but there is one problem still .... I am not creating a DLL from scratch. I have a project in VC++ (written by someone else) and I want to use it from my VC# code, so for that I first have to convert the VC++ project to a dll ~ right !! Or is there some other way I can use the project in my VC# code. Thanks once again.

        C 1 Reply Last reply
        0
        • S saania khan

          Thanks for the reply, but there is one problem still .... I am not creating a DLL from scratch. I have a project in VC++ (written by someone else) and I want to use it from my VC# code, so for that I first have to convert the VC++ project to a dll ~ right !! Or is there some other way I can use the project in my VC# code. Thanks once again.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          If you're converting to a dll, I assume you're hoping to access some classes in there, not execute any sort of UI ? You can compile with /clr and write a managed layer that you can import into C#. Which is easier really depends on the code you're working on.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          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