Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a dll file?

Status
Not open for further replies.

hubbabubba

Instructor
Mar 8, 2003
3
GB
HI,
can someone show me a step by step example of how to make a dll file, please? I understand its a long process and I will really appreciate the help of those that are willing to go through to show me.
 
hi,
please disregardmy fisrt message because I have found out how to create a Dll shortly after my post.Instead, I would like to know how to use it in a win32 C++ program. Can some one should me how to set it up and use it.
Suppose the dll file I created is named "MyFile.dll"
What do I write on the main.cpp file?
thankx in advance.
 
Hello!! You're right!! It's difficult to have a brief explanation about that, but I'll try...

OK, let's go thru a little program skeleton that can be useful for you...

DEVELOPING THE DLL:
(a DLL with a function called ReadConstant as example...)

1. Use Win32 Dynamic Link Library from File|new...
2. Use the template to create .cpp file
MyDLL.cpp
#include <windows.h>
BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason,
LPVOID Reserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{//This is sent the firt time the DLL is loaded
break;
}
case DLL_PROCESS_DETACH;
{//This is sent when the DLL is unloaded
break;
}
}
return TRUE;
}


Add functions after the above template

int ReadConstant(void)
{
return 49;
}
...

Add prototypes at the beginning of MyDLL.cpp such as:
int ReadConstant ( );
...

3. Customise MyDLL.def (Write a text file with DEF extension ant specify all the functions to export)

LIBRARY MyDLL.DLL
EXPORTS
ReadConstant
...
4. Build DLL
5. Remember that the name of DLL may be different from that of .cpp file name.

CALLING THE DLL IN C++ PROGRAM (DYNAMIC CALL!!):

//1. Add the lines to the top of the calling progarm (.cpp)
HINSTANCE gLibMyDLL = NULL;
Typedef int (*LPREADCONSTANT)(..);
LPREADCONSTANT ReadConstant;
...
//2. Load DLL
gLibMyDLL = LoadLibrary(&quot;MyDLL.DLL&quot;);

//3. Get the address of the function
ReadConstant=(LPREADCONSTANT)GetProcAddress(gLibMyDLL, &quot;ReadConstant&quot;);

//4. AT LAST!! Using the DLL function
int a=ReadConstant();

//5. When finish to use the library you must...
FreeLibrary(gLibMyDLL);

CALLING THE DLL IN VISUAL BASIC:

Declare Function ReadConstant Lib &quot;MyDLL.DLL&quot; ()as integer

Dim a as integer
a=ReadConstant
__________________

HOPE TO BE USEFUL!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top