what is the dll?? how can I make dll in c++?? Can we do everything with dll??
Printable View
what is the dll?? how can I make dll in c++?? Can we do everything with dll??
http://en.wikipedia.org/wiki/Dynamic-link_library
Depends on your IDE and compiler.
I have simple program.. I wrote it in c++.. its winapi.. can I convert it to dll??
A dll can contain any form of executable code, so yes.
But how depends on your IDE/compiler.
Sory I dont understand.. Sory my english.. and ask one more questions.. how can call or start the dll??
Well, as I mentioned. Creating a dll is different depending on what software you use to compile your applications.
Do you use an integrated development environment? For example, visual studio, code::blocks, Dev-c++, etc.
yes I use Microsoft Visual c++ 6.0
If you can, I would suggest you try upgrading to a later version of visual studio. Visual Studio 2008 Express is free and much more standards compliant than 6.0.
I can do simple guides based on the IDE.
That may answer what, but not how.
Create a new project
select either Win32 DLL (VS 6.0 or earlier) or blank project in VS2005+
if VS2005+ go to project properties and change the type from application(exe) to Dll
put _declspec(dllexport) before any varibles ro functions you want to export.
I have Microsoft Visual Studio 2008 full version but if I build my code in 2008 it needs framework if I build in 6.0 it doesnt need framework.. so I use 6.0 sometimes..
No, you don't. You can still write Win32 applications.
Don't use Windows Form projects - those are .net.
Ah yes, I don't have 6.0, so I can't show how in that old version...
That solves only half the problem.Quote:
put _declspec(dllexport) before any varibles ro functions you want to export.
Better do something such as:
That should ensure you can export and use functions (and classes!) from dlls.Code:#under EXPORT
#ifdef DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
EXPORT void myfunc();
It's the first step.
I create it in visual c++ 6.0 and write first part like this :
and I add my codeCode:#under EXPORT
#ifdef DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
I didnt write EXPORT but it didnt get error... yes.. how can I start my program?? :SCode:int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
DWORD nUserName = sizeof(acUserName);
GetUserName(acUserName, &nUserName);
kayit();
while(basla()==0)
Sleep(2000);
int some_dummy_var=1;
HANDLE Handle_Of_Thread_1 = 0;
Handle_Of_Thread_1 = CreateThread(NULL, 0, mythread, &some_dummy_var, 0, NULL);
WaitForSingleObject(Handle_Of_Thread_1, INFINITE);
return 0;
}
Notice that "#under" should be "#undef" too. A typo by me.
How are you doing this, however?
1) First you should create a dll. File -> New -> Project -> Win32 -> Win32 Project-> Dll.
2) Write your code. In the header, put "EXPORT" before your function prototypes.
3) Create another project - an application this time. Right-click the solution, select Add -> Project -> Win32 -> Win32 Application -> Win32 Project.
4) Include your header file where the functions from your dll are.
5) Call the functions as usual.
6) Now before we link and run, right-click solution and select properties. Goto project dependencies. Select your app from the list and tick the box next to your dll.
7) Press F7 to compile and link your app and it should work.
thanks for nice explain..
Note: Do not use lcc-Win32 to create a dll, it will not work. Also dlls can be called through rundll32, this doesn't support passing parameters though (if at all), so create functions that don't have any parameters if you are going to call using this method instead of through an app.
What are you talking about?Quote:
Note: Do not use lcc-Win32 to create a dll, it will not work. Also dlls can be called through rundll32, this doesn't support passing parameters though (if at all), so create functions that don't have any parameters if you are going to call using this method instead of through an app.
Elysia's solution is what most everyone uses and is nice and elegant b/c you don't have to change code to export/import. I just created over 20 DLLs in my project using this method and it works just fine.
Linking with DLL export libraries is the easiest way to export classes and objects from DLLs. It requires no source code changes for the modules using the DLL. If you have a module with a bunch of C functions I would recommend compiling those as good old static libraries.
The only thing you cannot do easily in MSVS is export STL container instances across DLL boundaries and/or any template instances. Since you would be unwise to allow access to your underlying containers in the first place this should not be an issue. I also cannot fathom why you would ever allow access to a template instance so you should be ok there too. Note that this only applies to instances not the objects in the container. You can provide public methods to get the objects in an STL container that are within a class that is inside of a DLL. You can also export the instance of the container albeit with some very ugly code and export statements. I would recommend against it.
It's also not a good idea to allocate memory in a DLL and de-allocate it in another DLL. Microsoft claims if you use virtual destructors you should be ok but you will still get the scalar deleting destructor warning. Essentially MSVS is saying you have a new/delete mismatch. For more information you should look up the error message on MSDN.