calling a function in DLL file ???

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 51
Reputation: Jacky1 is an unknown quantity at this point 
Solved Threads: 2
Jacky1 Jacky1 is offline Offline
Junior Poster in Training

calling a function in DLL file ???

 
0
  #1
Nov 8th, 2008
I did make my dll file out off those two files

dll.h
  1. #ifndef _DLL_H_
  2. #define _DLL_H_
  3.  
  4. #if BUILDING_DLL
  5. # define DLLIMPORT __declspec (dllexport)
  6. #else /* Not BUILDING_DLL */
  7. # define DLLIMPORT __declspec (dllimport)
  8. #endif /* Not BUILDING_DLL */
  9.  
  10. DLLIMPORT void welcome();
  11.  
  12. class DLLIMPORT DllClass
  13. {
  14. public:
  15. DllClass();
  16. virtual ~DllClass(void);
  17.  
  18. private:
  19.  
  20. };
  21.  
  22.  
  23. #endif /* _DLL_H_ */

and dllmain.cpp

  1.  
  2. /* Replace "dll.h" with the name of your header */
  3. #include "dll.h"
  4. #include <windows.h>
  5. #include<iostream>
  6. using namespace std;
  7. DllClass::DllClass()
  8. {
  9.  
  10. }
  11.  
  12.  
  13. DllClass::~DllClass ()
  14. {
  15.  
  16. }
  17.  
  18. DLLIMPORT void welcome()
  19. {
  20. cout << " Welcome home " << endl;
  21. }
  22.  
  23. BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
  24. DWORD reason /* Reason this function is being called. */ ,
  25. LPVOID reserved /* Not used. */ )
  26. {
  27. switch (reason)
  28. {
  29. case DLL_PROCESS_ATTACH:
  30. break;
  31.  
  32. case DLL_PROCESS_DETACH:
  33. break;
  34.  
  35. case DLL_THREAD_ATTACH:
  36. break;
  37.  
  38. case DLL_THREAD_DETACH:
  39. break;
  40. }
  41.  
  42. /* Returns TRUE on success, FALSE on failure */
  43. return TRUE;
  44. }

now I want to call welcome() function in this DLL from my test_main.cpp

main.cpp
  1.  
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include<project3.dll> // <<---------- the dll file include
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. welcome(); // <<------ this function in the DLL
  11. system("PAUSE");
  12. return EXIT_SUCCESS;
  13. }

but I got those errors

  1.  
  2. 3 \including dll\main.cpp project3.dll: No such file or directory.
  3. 9 \including dll\main.cpp `welcome' undeclared (first use this function)
  4.  

I have project.dll in the directory

And when I made the dll file I didn't have anyfile *.lib

I only have a file libProject3.def I tried to include it but it won't work either

any advice please ?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: calling a function in DLL file ???

 
0
  #2
Nov 8th, 2008
include the dll.h header, and not the project3.dll file.

Make an import library - the .lib file, should be an option in your compiler/linker

link the .lib file into your project. The program will know how to access the .dll file from the details stored in the .lib file.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 51
Reputation: Jacky1 is an unknown quantity at this point 
Solved Threads: 2
Jacky1 Jacky1 is offline Offline
Junior Poster in Training

Re: calling a function in DLL file ???

 
0
  #3
Nov 8th, 2008
Originally Posted by dougy83 View Post
include the dll.h header, and not the project3.dll file.

Make an import library - the .lib file, should be an option in your compiler/linker

link the .lib file into your project. The program will know how to access the .dll file from the details stored in the .lib file.
Thanks man I found out that the lib file was with extinction .a and I just linked in the project options as you said

Thanks again
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC