Hi,
I have a C code for which i have to generate dll but i myself chose to do it in vc++ (visual studio 2008). I thought i have succeeded in doing that but i wasn't. I found that when i wrote a test application to refer that dll. when i tried to add a reference in test application it says that "could not add a reference to the file chosen because it is neither a .Net assembly or registered ActiveX control".
Can anyone tell me what's the problem or is this the way to do or else did i do something wrong? Earliest response is appreciated.
Loading
VulpesPosted Feb 8, 2012, 1:50 PM
I'd follow the instructions in this article to create the dll:
http://www.codeproject.com/Articles/9826/How-to-create-a-DLL-library-in-C-and-then-use-it-w
To use it from VBA, you'll then need to include Declare statements for each C function you need to call. You're probably familiar with this already (similar to DllImport in C# or VB.NET) but, if you're not, this link should help:
http://msdn.microsoft.com/en-us/library/aa165080(office.10).aspx
Sam HobbsPosted Feb 8, 2012, 7:20 PM
One useful thing that the code generated this way has is the macro that simplifies use of __declspec(dllexport) / __declspec(dllimport).
I suggest creating your C DLL project by generating a new project in the manner I describe instead of using that CodeProject article written by someone that did not yet have a lot of experience. Many developers, including myself, write articles about subjects we have just finished spending time learning but for this you can benefit from the immense experience of Microsft developers by using Visual Studio to generate a starter project.
Sam HobbsPosted Feb 8, 2012, 6:23 PM
I suggest starting by generating a DLL project using Visual Studio. It does a good job of generating a skeleton DLL project. You will need to conver the code to C from C++ but that should be easy to do.
Karthik AgarwalPosted Feb 8, 2012, 12:34 PM
And regarding /clr i am using clr only if that's not correct i can change that to /clr pure.
To make to more clear about what my application is, i want to create a dll with the C code i have using any way and finally i want to use that as an interface to VBA (Excel application) from where it will called. This is what is my need and should tell me how to proceed i haven't this kinda of thing till now. I worked with dll's but not with C code. Previoulsy i created a dll using VB and used in VC++ and VB as well but never tried with C code. But now i need to do it with C code.
And also congrats for becoming top contributor.
VulpesPosted Feb 8, 2012, 12:02 PM