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

Including an import library (.lib) in MFC 3

Status
Not open for further replies.

SulikSlayer

Programmer
Nov 16, 2002
17
KG
How am I supposed to do this?
I would also be thankful for some info about including .dll-s
Now i have to declare an extern function in .dll, and then use a function-pointer to call it by it's adress. Is there any other way to do that more easy?
But, again, including libs is the main question.
Thanks :)
 
For a .lib, you have to go in the Visual Studio IDE menu in Project->Settings, select the Link tab and write the name of the file you wish to use. If the library is in another directory, select in the combo box present in this tab "Input" and then write the path to the library in the field "Additional library path".
I'm afraid that for a dll that's the only way...
 
Regarding the lib inclusion Go to the project settings Give the path of the header file in the C/C++ --> preprocessor-->Additional include Directories(The path of .h file).

In Proj settings -->Link-->Input-->Additional Library Path, Give the path of the *.lib file.

Call the function as Usual.

Hope this Might help U....

Reg Dll same steps except we have to Load the Dynamic Link Library.... I will post the code later.
 
thanks, guys! :)
Now i'll try that..
by the way, there's no "Additional Library Path" in my Linker tab. Perhaps it's because I use Visual Studio .NET?
But I suppose it'll work if I specify the path in the "Additional dependencies" field.
 
Oh, I'm sorry. I presumed that you used VC 6.0. In VS.NET you use Additional dependencies, as you guessed.
 
The easiest dll's to use are extension dll's. You don't need to 'export' a particular function - you can 'export' the entire class! This is done very easily:

You simply add AFX_EXT_CLASS before the class name in your class definition, eg:
[tt]
class AFX_EXT_CLASS CClassName
{
public:
// Function definitions
};[/tt]

Once you have built your dll around this class and imported the necessary .lib file (as per instructions from post above) and #included the header file, you can use the entire class from the dll as if it were part of your .exe code!

No need to obtain pointers to functions or anything like that. This is the easiest way.

[rockband]
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Well, I tried it out..
..And nothing happened!
I tried to:
1) Add .lib file (with full path) to the Advanced Dependences combo box
2) Add .lib file (full path) to the Linker -> Advanced -> Import Library box
3,4) Add .dll file (full path) to both boxes

Neither of these helped.
Perhaps I didn't declare my function right?
I have an MFC dll named MFCdll, and in the file MFCdll.cpp i define a function

int ImportFunc(int x) {return x*2;}

I try to use it in my application - nothing happens. Compiler said that this is an undeclared identifier.

I tried to declare a class in the ImportClass.h file, with no .cpp file, both constructor and destructor inline, and also an inline function IncludeFunc.

I cannot include this file in my MFCapp - when I try to, the compiler ends to understand the other includes, which refer to the MFC. Compiler gives me a load of errors, and I cannot understand why.

What the heck is going on??
P.S. If u didn't understand what I mean or u need any additional info about my .dll and MFCapp - feel free to ask, 'cause I really need to solve this problem :)

Thanks in advance!
 
Hi Sulikslayer,
regarding the Dll export/import there is aprocedure to use the function in a dll. we need to export a function to use it outside the Dll.

If needed paste the code u want in Dll here.
or else U go thru dllexport/dllimport in msdn.

U have to do these or use *.def file to export a function.
If u still not clear after going thru MSDN i will help U with the code u have pasted.
 
I'll try to get info in MSDN.
If I won't paste the code - than I am successful :)
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top