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
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
-
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
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.
-
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.
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