well one probeblem solved. Just confuses me tho...hwo the heck did you get a .lib file. wouldn't you want a .dll file? oh well...
well one probeblem solved. Just confuses me tho...hwo the heck did you get a .lib file. wouldn't you want a .dll file? oh well...
Also looking at the code you posted, you need to make sure BUILDING_DLL is defined.
A .lib file makes it easier to use .dll files. With a .lib file, all you have to do is add the header to your program that uses the .dll, and link to the .lib. Then you can call the exported classes/function normally. It makes it easy
If you dont have a .lib file (just the .dll), then you have to use the functions:
LoadLibrary()
and
GetProcAddress()
to call the .dll functions.
alright ok scratch the other code. I have 3 files now. The dll.cpp, dll.h, and chichi.cpp (my main file).
Here is the code for all 3...
Code:dll.h #ifndef _DLL_H_ #define _DLL_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ void test(); #endif /* _DLL_H_ */
dll.cpp
Code:/* Replace "dll.h" with the name of your header */ #include "dll.h" #include <windows.h> #include <iostream.h> #include <conio.h> void test() { char player[100]; cout<<"Player: "; cin>>player; cout<<"\n"; if(!strcmpi("hello", player)) { cout<<"hi"; cout<<"\n\n"; } getch(); }
chichi.cpp
Code:#include <iostream.h> #include <conio.h> #include <fstream.h> #include "dll.h" int main() { test(); }
Ok I know now that the chichi.cpp won't work. But any sugestions on how to make a library using ONLY dev-cpp or just any plain sugestions?
I found it on google:Originally Posted by Hunter2
http://www.google.com/search?hl=en&i...ionable+DLL%22
Maybe it was just temporary.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
wierd
I've never used Dev C++, so I cant give you the specifics unfortunately. But here is the steps you need to do (you can probably use google to figure out how to do each step).
First you need to compile dll.cpp and dll.h into a into a dll. There will be a command line option on Dev C++ that you pass to the linker in order to accomplish this. (For instance on MSVC++ it's /dll).
Next you will use the dll in chichi.cpp. How you do this depends on whether Dev C++ gives you a .dll only, or and .dll and a .lib. If you have the .lib file, then your chichi code is correct as it is. The only additional step you need is to link or your dll.lib file.
If you only have the dll file, then your chichi.cpp code needs to be change to this:
Notice how if we are just using the dll (not the .lib file) we dont need to include dll.h in chichi.cppCode:#include <iostream.h> #include <conio.h> #include <fstream.h> int main() { void(*ptestfn)(); HMODULE hMod = LoadLibrary("dll.dll"); if(!hMod) return 0; // failed to load dll // we need to get the address of the test() function that is // inside our dll ptestfn = (void (*)())GetProcAddress(hMod,"test"); if(ptestfn) ptestfn(); // call function }
alright I'm doing homework right now so I'll check back in a little bit and you use MSCV++ right? Is it free and were can I get it?
Im afraid not... thats Microsoft teritory right there, and the CHEAPEST I have ever seen it was $75, and that was an old version.MSCV++ right? Is it free
Newer versions will run you over $100, well, until the Express edition comes out.
alright that wrecked my night, jk. I will make due with dev-cpp.
oh and your code up there doesn't work.
Edit: The question I should ask is how do I make a .lib file with dev-cpp?
Last edited by Rune Hunter; 09-08-2004 at 07:19 PM.
Sang-Drax: Yes. Actually, I later realized that I had the wrong search string.
bithub: I'd already done that (add to link tab) but was getting unresolved externals still. It wasn't till a few moments ago that I realized the linker will give a different error for missing library files Ok, well, I sort of fixed the problem by making all the functions in the DLL 'extern "C"' (it'll link properly now, apparently the problem WAS in decorated names I guess). But then there's the problem that, seemingly, overloaded functions are not allowed with this method (I suppose that would have something to do with naming conflicts when the names aren't decorated). I thought in MSVC's docs it said that __declspec(dllexport) eliminates the need for extern "c", or at least solves the decorated name problem. Any ideas?
**EDIT**
Rune: I believe it's supposed to generate a .lib alongside the .dll file.
**EDIT2**
More strangeness. Apparently now it works without the "extern "C"". Perhaps I had the wrong version of the .lib in the folder...
Last edited by Hunter2; 09-08-2004 at 07:29 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
extern C shouldnt matter in this case. extern C is used when you are exporting a C++ function that you want to be called from C code. The extern C command tells the compiler to use normal C naming for the function instead of C++ mangling.
Rune >> Not sure what you mean by "the code doesnt work". You will need to go into more detail than that
Right, I was reading up on that in the compiler docs... It's also used for easier .DEF file writing, so you don't have to find the decorated names. Although I still have no idea how the .DEF files workThe extern C command tells the compiler to use normal C naming for the function instead of C++ mangling.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
DEF files just specify what functions are exported by the dll. You can effectively do the same thing by putting __declspec( dllexport ) before your function. Most people use __declspec( dllexport ), and dont use def files.