Friday, January 9, 2009

How to create a dll

If you are interested in this post then I assume that you know what is a dll, if not you can find a definition here.

Below I will give you an empty framework of what you need to create a dll.

There are two files: mylib.c (that contains your functions) and mylib.def that contains the functions that you want to make accessible for other programs (the exported functions).

mylib.c
#include "stdio.h"

__declspec(dllexport) int __stdcall myFunc()
{
printf("Text from my dll\n");
return 0;
}


__declspec(dllexport) int __stdcall DllMain()
{
return 0;
}

The mylib.def will contain:
LIBRARY mylib
EXPORTS
myFunc

Now you need to compile your mylib.c file with the following switches:
cl mylib.c /LD /O2 /Gz /GD /W3 /link advapi32.lib /DLL /NOLOGO /DEF:mylib.def /RELEASE

Enjoy :)

- From ExpertSec

No comments: