It mentioned that any applications referencing the DLL would have to be rebuilt if .DEF files were not used though.
It mentioned that any applications referencing the DLL would have to be rebuilt if .DEF files were not used though.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
guess my posts are importent for more then just me. But!... what I mean by not work I mean it doesn't work. It doesn't compile there are alot o errors. It just doesn't work.
post what errors you are getting, and I will try to help you through it.
ok now here is the code that doesn't work if anyone gets confused...
Code:#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 }
Now here is a opy of the error window...
Ok... I just found out there are NO errors and it DOES compile...
But!!!, It doesn't work. Now the thing is when I have a .dll file thing being made and before I compile it askes for a host file. I can only select a .exe already made and without selecting one I can't compile it. So that is my first probeblem. And when I do compile it using a already made .exe host file it only shows black with the DOS curser thing in the DOS window and blinks and does notin no matter what. And I can't close the program through the program only clicking the X. So any help now?
I am assuming that you do have a function called test in your dll?
What is C++?
dll.h...
dll.cpp...Code:#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_ */
Here is my main .cpp file again...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(); }
Code:#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 }
Last edited by Rune Hunter; 09-09-2004 at 04:13 PM.
Change your code to this so that we can see if there are any problems loading the dll or finding the function:
Code:#include <iostream.h> #include <conio.h> #include <fstream.h> int main() { void(*ptestfn)(); HMODULE hMod = LoadLibrary("dll.dll"); if(!hMod) { printf("Error loading dll\n"); 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 else printf("Unable to find function\n"); }
still need a host file and when I do it is only blank like I said before...
ok, I see your problem. You need to export the test function. Change the dll code to:
Also add DLLIMPORT to the beginning of the test() function definition.Code:#ifndef _DLL_H_ #define _DLL_H_ #define BUILDING_DLL #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ DLLIMPORT void test(); #endif /* _DLL_H_ */
Two problems I can think of. One is that test() isn't declared as DLLIMPORT, and therefore isn't DLL-import-able. Second, it's not declared as extern "C", so the name gets mangled up and you won't be able to load it using GetProcAddress() as simply "test"... it'll be "ta1@$!e$$s23t" or something, which you need to find somehow.
**EDIT**
Now I see why the tutorial used extern "C" in all its examples... it's so that they would work with the LoadLibrary method. Because if you have overloaded functions and they have the same name, then you're in deep doodoo when you try loading "test" and there's 3 of them with different implementations.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Ok, Im not sure why it's asking for a host file. If all you are doing is building the DLL (Not debugging it), then you shouldnt need any sort of host file.
lol... what IS a host file? Hah! **vanishes to google**
**EDIT**
"creating dll compile host file" results... "Trojan virus" "Virus alert" "How to prevent hacker access" "securing your system from invasion" "the end of the world is near" "don't press the button!" "AHH THE NUKES ARE FLYING!!" "NOO THE ROBOTS ARE COMING!!!"
Last edited by Hunter2; 09-09-2004 at 04:23 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Im not sure what dev-cpp is calling a host file, but I can make a guess
Debugging a DLL cant be done like a normal exe file. You need an exe file to load the dll in order to debug it. Im guessing the host file is just an exe file which loads the dll, and therefore can be used for debugging. Like I said before though, I've never used dev-cpp, so it's just a guess
Sounds like a good guess to me. Maybe turning off debug options will get rid of the host file prompt...
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Go to
Tools > Compiler Options > Settings > Linker > Generate Debugging Information ( NO )
What is C++?