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