Solved

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

Posted on 2001-06-06
6
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 51
sumDigits challenge 9 178
EvenOdd challenge 10 159
MaxSpan challenge 9 138
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

739 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