How long does it take to build the dll.h file?
How long does it take to build the dll.h file?
Shouldnt take but a couple of seconds.
Something might have went wrong somewhere.
What is C++?
There is a reason we are doing it this way. Check out the first page of this thread.you should probably just link the lib and screw manually loading the functions altogether
well I got the probeblem and fixed it...now I have anoutehr probeblem. Why won;t it rebuild!!??!!?? I can't compile it only rebuild and that just never ends. The program is working... but no dll.
Do you know how you would load a class? I though maybe you could create a pointer and assign it to the classes address in the dll but couldnt figure out how.
[edit]
RUNE I would start over, delete all of your files that have to do with this dll and start over.
[/edit]
What is C++?
lol I did. nd this is what happened. I got the 3 files, dll.h, dll.cpp, and the main .cpp file. And well I;ll keep trying stuff...
Sometimes, when your trying to figure out stuff your file and your code will get all cluttered and you will become confused and nothing will make sense.
So here, A little step by step refresher...
- New Project
- DLL
- - Modify the dll.h and dll.cpp
- - Hit Compile
New Project
- Console App
- - Write the code to load the DLL and use if statements to catch errors.
Let us know what happens
What is C++?
Check out this article:Do you know how you would load a class? I though maybe you could create a pointer and assign it to the classes address in the dll but couldnt figure out how.
http://codeguru.earthweb.com/win32/dyndllclass.shtml
but I don't want to use classes. I want to use functions...
We realize that. His question was just for his own curiousity.but I don't want to use classes. I want to use functions...
ok I ddi what you said...
So here, A little step by step refresher...
New Project
- DLL
- - Modify the dll.h and dll.cpp
- - Hit Compile
New Project
- Console App
- - Write the code to load the DLL and use if statements to catch errors.
Let us know what happens
I did it all and NOW the dll.h and dll.cpp files compile just FINE! But now (I used a sorce file instead) and it compiles but then it sits there, I go to the log, and it says compling please wait.. or something and then says the directory it is "compliling" to... It stays tehre for ever. then if I hit cancle I get 433 errors. and at the end of the error lists it says something like "There must some horibly wrong wiht your code, plese fix it".
Now what?
here si my code...
dll.h...
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 */ DLLIMPORT 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> void test() { cout<<"It worked!!!!"; } BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } /* Returns TRUE on success, FALSE on failure */ return TRUE; }
mainfile.cpp...
Code:#include <iostream.h> #include <conio.h> #include <windows.h> #include "project1.dll" int main() { test(); getch(); return 0; }
Alright now lets get some things traight right away!...
No matter what I put in the mainfile.cpp it will give that error. I tried many many things but notin worked. So please don't say notin there I only have that becuase that is what I tried last.
Thanks alot still, your really helping me alot! (says in a non sarcastic way)
Last edited by Rune Hunter; 09-10-2004 at 03:08 PM.
Ok, I'm downloading the dev-cpp compiler right now. Once I've finished, I will try to give you step by step instructions.
changes are bold
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 */ extern "C" DLLIMPORT void test(); #endif /* _DLL_H_ */Now you cannot do a #include "dll.dll"Code:/* Replace "dll.h" with the name of your header */ #include "dll.h" #include <iostream> DLLIMPORT void test() { std::cout<<"It worked!!!!"; } // The message function thingie is not needed
It wont work.
Create a function pointer like in my main.cpp example up there.
[edit]
Oh, and dont putCode:#include <windows.h> #include <iostream> int main() { // Function Pointer void(*TextFunc)(); // Load DLL HMODULE hMod = LoadLibrary("TestPlug.dll"); // Make sure its loaded if(!hMod) std::cout << "Error Loading DLL"; // If it is.. else { // Assign the function pointer to the // address of the function in the dll TextFunc = (void(*)())GetProcAddress(hMod, "test"); // If it found it if(TextFunc) TextFunc(); // If not else std::cout << "Error Finding Function"; } std::cin.get(); return 0; }
in your code.Code:#define BUILDING_DLL
DevCpp automatically defines it via compiler linker option. If you were to put it in your code, you would never be able to use it "correctly"
Last edited by Vicious; 09-10-2004 at 03:24 PM.
What is C++?
I got it...
Did it work? Finally!?
What is C++?