Solved

How to use a DLL without the *.h and *.lib files...

Posted on 2001-06-06
6
370 Views
Last Modified: 2013-11-20
I understand that to use a DLL, i should have a *.lib and a *.h file along with the dll file... Is there a way i can use a dll without the other two files present?  I want to use an existing dll, problem is there are no .lib and .h files available for the dll...

Im new at this... please help...

Thanks...
0
Comment
Question by:3Mann
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6159864
You need to know the parameters for any functions you need in the DLL but you DO NOT need any .lib or .h files to use a DLL.

You can load the DLL using LoadLibrary() and find any function in it using GetProcAddress().

After that, however, it's up to you to make sure you call the functions with the proper calling convention, proper parameters, and proper return type.  That's where the .h file is very handy.  The .lib file has export information that the linker can use to make this almost transparent.

But....neither of these are required.
0
 
LVL 1

Author Comment

by:3Mann
ID: 6162068
Jhance,
Thanks for the info... But im new at this...
Im trying to create an OCX...  Where would i be calling LoadLibrary()?  Should it be in the initInstance method?

btw, im increasing my points... this seems hard... (for me anyway... =))
0
 
LVL 1

Author Comment

by:3Mann
ID: 6162078
cont...

Or would it be in the constructor for the control...
if it can be placed in both methods... where would it be most adviceable...

Thanks again...
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Accepted Solution

by:
gilad_no earned 75 total points
ID: 6164461
Suppose you have a dll called: MYDLL.DLL and a function:

int Test(CString szStr,int nX,int nY);


you need to add the following code:

typedef int (TestProc)(CString,int,int);
HINSTANCE hLib=LoadLibrary("MYDLL.DLL")
if (hLib==NULL)
 return;
TestProc *Test=(TestProc*)GetProcAddress(hLib,"Test");
if (Test!=NULL)
{   // Here we will call the function
   CString szStr("Test string");
   int x=0,y=0;
   int result=(*Test)(szStr,x,y);
{
FreeLibrary(hLib);
0
 

Expert Comment

by:gilad_no
ID: 6164470
cont...

If you use the "Test" function many times, you can load the library in the constructor and free it in the destructor.
If you intend to use it once, you can load it, use it and free it from memory. This will save system resources
0
 
LVL 1

Author Comment

by:3Mann
ID: 6170012
what a complete answer...
i have to also give credit to jhance also...
thanks jhance... but if its ok.. im giving my points to gilad...

btw, i already acquired a .h and a .lib... so this lessens my prob... =)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now