it is on No. Oh I'm screwed...and that dll.h replacement stilld on't work. I think I might need the extern c thing, But how do I do that?
it is on No. Oh I'm screwed...and that dll.h replacement stilld on't work. I think I might need the extern c thing, But how do I do that?
ROFL I think I just figured out your problem...
Hit ctrl+F0 to compile...
I bet you did what I did and hit just F9.
What is C++?
F9... run? As opposed to ctrl-F0 for build?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Yeah F9 is compile and run, ctrl + F9 is compile
What is C++?
Ok I got it to work.
**dll.h**
**dllmain.cpp**Code:#ifndef _DLL_H_ #define _DLL_H_ extern "C" #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_ */
And thats the plugin. And heres the program that uses it.Code:/* Replace "dll.h" with the name of your header */ #include "dll.h" #include <iostream> DLLIMPORT void test() { std::cout << "Plug IN!"; }
Code:#include <windows.h> #include <iostream> int main() { void(*TextFunc)(); HMODULE hMod = LoadLibrary("TestPlug.dll"); if(!hMod) std::cout << "Error Loading DLL"; else { TextFunc = (void(*)())GetProcAddress(hMod, "test"); if(TextFunc) TextFunc(); else std::cout << "Error Finding Function"; } std::cin.get(); return 0; }
What is C++?
You didnt have to prefix extern "C" to the function for it to work vicious?
Nope.
EDIT: Er, wait, I did include it in the dll.h, I forgot about that.
I'll try it without it.
lol, now I cant get it to work period.. jeez.
EDIT2:
Yeah ok, you need to put extern "C" for it to work. But I gusee you can just do it "Globally" and not per function. I tried it both ways.
Last edited by Vicious; 09-09-2004 at 10:56 PM.
What is C++?
try prefixing extern "C" to the function declarations and definitions.
Ok, i'm foiled again...
HERE is what works...
You must put extern"C" before each function prototype.
Here is more accurate code
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 Text(); extern "C" DLLIMPORT void Text2(); #endif /* _DLL_H_ */On a side note, if your using Dev-C++ its a good idea to "Rebuild All" instead of just compilng it. (When you make changes to it).Code:#include "dll.h" #include <iostream> DLLIMPORT void Text() { std::cout << "Plug in"; } DLLIMPORT void Text2() { std::cout << std::endl; std::cout << "ah"; }
I have a feeling that trying to use classes would be very different.
What is C++?
>>You must put extern"C" before each function prototype.
Actually, there's supposed to be some way to find the compiler's mangled name for your function when you compile the .dll. Then instead of putting extern "c", you could use the mangled name in GetProcAddress() I guess you should probably stick to extern "c"... But come to think of it, you should probably just link the lib and screw manually loading the functions altogether.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
lol wow you all did aot when I was at school. I'll try the code above and see if it works...for me...
ok I tired the code and well guess what!? It didn't work. I code must be right by now but the host file is screwing everything up...
Ok first thing crtl + f9 didn't do anything mroe then hiting compile. I know for sure the host file is screwing everything up.
Make SURE you compile and not compile and run the DLL.
What is C++?
It takes a long to rebuild but I think I might have got it to work finally! If this does work then I will be the biggest idoit this week....
Yeah, i'm used to hitting f9 to compile and run my programs. I did that same thing with the dll and just started laughing.
What is C++?