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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

importing functions of DLL?

Status
Not open for further replies.

rpk2006

Technical User
Apr 24, 2002
225
IN
I created a DLL file and added it to my project. I also created a .DEF
file with the following lines:

--------------
LIBRARY K.DLL
EXPORTS
HASH
--------------

I also added a .H file with the following lines:

code:
#ifndef KDLL_H
#define KDLL_H

/* Hash the text */
void HASH(CString s);

#endif /* KDLL_H */



I also added following line in my CPP file:

code: extern "C" void HASH(CString s);



I included this header file in my .CPP program, but still not able
to access the DLL file function HASH.

What's the problem?
 
You should use LoadLibrary() and GetProcAddress() functions.
 
So, some simple rules
1. Forget about .DEF files
2. forget about LoadLibrary, GetProcAddres....
3. Inside your dll roject use header like this:
#ifndef KDLL_H
#define KDLL_H
/* Hash the text */
__declspec(dllexport) void HASH(CString s);
#endif /* KDLL_H */
4. Inside the .exe use use header like this:
#ifndef KDLL_H
#define KDLL_H
/* Hash the text */
__declspec(dllimport) void HASH(CString s);
#endif /* KDLL_H */
4. When you compile your dll, are generated two files, yourdll.dll and yourdll.lib, you should link your .exe with yourdll.lib.
6. LoadLibrary/GetProcAddress you will use when in special cases, especially when you wand to do it explicitly.


Ion Filipski
1c.bmp
 
IonFilipski,

Thanks for you clear answer. I modified my project as you suggested and also added the .LIB file into my application project along with the DLL file. But as you say, "link the DLL with LIB file", how to do so. Do I need to set the dependency, or what.

Secondly, even after adding all the files in the project, the VC++ IntelliSense is not showing functions of the DLL file.
 
When Ionfilipski said "Link the EXE with LIB file" he means, go to Project Settings, and in the Link tab, where it says "Object/Library Modules" type XXXXX.LIB, where XXXXX is the name of the DLL project.

As far as the second concern, just know that the coding aids in VC++ are very quirky. I don't think it autocompletes for external headers (except for standard windows headers). For example, it doesn't autocomplete functions in the DirectX or FreeType libraries.

But this is just an inconvenience--and since you wrote the library, you probably know it well enough to not be completely dependent on coding aids.

I REALLY hope that helps.
Will
 
I entered the name of the .LIB file, but still whenever I try to call the function contained in a DLL, I get an error "Unresolved .....<function name>
 
I think I must send my project to you "IonFilipski" and "apatterno", since I did all types of permutations and combinations.

Tell me how to send the code to you.
 
My contact information is written in my details, click on my name on the top of current post

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top