Solved

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

Posted on 2001-06-06
6
385 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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