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

problem using VC++ DLL in VC#

Scheduled Pinned Locked Moved C#
csharpc++helpquestionvisual-studio
5 Posts 2 Posters 2 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

      I just answered this, did you cross post, or was my reply lost ? It's not a COM dll, so regsvr won't work. You need to make it a COM dll, make it a managed DLL, or use p/invoke to call it's methods from C#.

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

      S 1 Reply Last reply
      0
      • C Christian Graus

        I just answered this, did you cross post, or was my reply lost ? It's not a COM dll, so regsvr won't work. You need to make it a COM dll, make it a managed DLL, or use p/invoke to call it's methods from C#.

        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

        Yeah thanks once again, I posted it in 2 different threads.... The point I didnot mention in the other reply is that I am using PInvoke in C#. That is where I started from, and when that didnt work I had to look into what other stuff could be wrong. I am using ... [System.Runtime.InteropServices.DllImport("testdll.dll")] static extern int fntest (); and in the main I am simply doing .... int x = fntest (); and this is where I get the error ... EntryPointNotFound exception. It says "unable to find entry point named "fntest" in DLL "testdll.dll". I even tried using System.Reflection.Assembly.Load Method, which throughs a TypeLoadException. Please help me out here. I would highly appreciate it. Thanks,

        C 1 Reply Last reply
        0
        • S saania khan

          Yeah thanks once again, I posted it in 2 different threads.... The point I didnot mention in the other reply is that I am using PInvoke in C#. That is where I started from, and when that didnt work I had to look into what other stuff could be wrong. I am using ... [System.Runtime.InteropServices.DllImport("testdll.dll")] static extern int fntest (); and in the main I am simply doing .... int x = fntest (); and this is where I get the error ... EntryPointNotFound exception. It says "unable to find entry point named "fntest" in DLL "testdll.dll". I even tried using System.Reflection.Assembly.Load Method, which throughs a TypeLoadException. Please help me out here. I would highly appreciate it. Thanks,

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

          A C++ dll contains an export file, which is just a text file that lists the methods that are exported. I suspect that's what you need here.

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

          S 1 Reply Last reply
          0
          • C Christian Graus

            A C++ dll contains an export file, which is just a text file that lists the methods that are exported. I suspect that's what you need here.

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

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

            Thanks a lot Christian. I tried to follow the stuff explained in http://www.icynorth.com/development/createdlltutorial.html. My DLL did not work with my C# code (even though I had everything told in the article), but when I copied the DLL that came with the article, it worked fine with VC# project, by simply using PInvoke !!. I'll follow the setting in the given project more closely and see where I am going wrong. Thanks a lot for your time and help. Saania

            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