?
Solved

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

Posted on 2001-06-06
6
Medium Priority
?
410 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Accepted Solution

by:
gilad_no earned 300 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

Independent Software Vendors: 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!

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 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