This article shows a step by step technique to create your first DLL with VC++. Steps to create your first DLL Create a Win32 Dynamic Link Library project Go to the workspace explorer. If its not visible in the GUI go to the View menu and click on WorkSpace or use Alt + 0 shortcut to make it visible. Go the FileView tab and add a source file (Dll.cpp) and a header file(Dll.h). Add following into Dll.h Code: # include <afxwin.h> class _declspec(dllexport) CDll { public: void ATestMethod(); }; Add following into Dll.cpp Code: #include "dll.h" void CDll::ATestMethod() { AfxMessageBox("CDll::ATestMethod of a dll is invoked"); } Now create a new Win32 Console application and create it in such a manner that the output folder of both them remains the same so that you dont need to link the dll manually through the lib. Easy way of doing this is create a blank dsp file and insert that into the current workspace. Then add the main.cpp file into the project. Add the following code into the main.cpp file Code: #include "dll.h" void main() { CDll dll; dll.ATestMethod(); } Go to Project > Dependencies and set the Win32 console project is dependent on Win32 Dll project Thats all is needed. Simple isnt it. I am attaching the sample for your convenience and explore more.
Hallo, I understand this code, but I am wandering how to load and use a DLL file, that we have created. For Example: Code: //makedll.cpp #define EXPORT extern "C" __declspec(dllexport) EXPORT double sqr(double x) { return x*x; } after i compile this code i recieve a makedll.dll file. Now how can I use the function in this DLL file? Something like this....? Code: //testdll.cpp #include <cstdlib> #include <iostream> #library makedll.dll extern "C" double sqr(double); int main(void) { double num; printf("STARTing the program"); printf("\n Enter a number:"); scanf("%f",&num); printf("\n The square of the number is:%f",sqr(num)); system("PAUSE"); return EXIT_SUCCESS; }
It was a mistake from my part regarding the above article. Thanks for pointing out that. I have corrected it so that it should read what its intended to. The sample was correct as far as implmentation goes but I put the wrong code snippet you need to put in main.cpp file and I have corrected that.
Dont jump into the article with your query. Instead have a seperate thread for your query in the Forum.
Hi I am new to dll file. I get stuck with building a dll (C/C++) file to be call from C applications in VS.NET 2003 for my project. Does anyone know how to import it , something like extern "C" __declspec( dllexport ) int MyFunc(long parm1);. I try to do it but it just didn't work. Practical examples would be really good!! many thanks
If you have any query with relating to article you should be discussing here and if you have a seperate query you can always use the Queries and Discussion forum for your queries. That helps in 2 ways. 1. All the experts can see and help you. 2. Other persons searching for something can also get the help.
could u tell me please how to do it in some details,cause i have a dll file which deal with parallel ports but i don't know how to use it cause i don't know any thing about the inside functions Regards
Please post your query as a separate thread with proper title. If you have anything relating to the article it should go here.
pls shabbir is the dependency viewer a tool in visual studio or it's external application if so could u tell me from where i can download it cause i have a dll file dealing with parallel port but i don't know any thing about the functions it contains
How can i reach it,i tried to find it but i'm failed can u pls tell me where can find this application
Again I will tell you should have separate thread for the query and not use the same article for it. If you are not willing to create the thread sorry but I cannot just answer it here.