DLL and Application

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

Join Date: Nov 2007
Posts: 290
Reputation: kv79 is an unknown quantity at this point 
Solved Threads: 7
kv79 kv79 is offline Offline
Posting Whiz in Training

Re: DLL and Application

 
0
  #11
Dec 20th, 2007
Originally Posted by Ancient Dragon View Post
Did you create a DLL project when you got to the window that listed all the different project types? I did, then tried to compile what Dev-C++ generated and got an error that the linker can not find dllcrt0.o even though its in the lib directory. I'm trying to find the solution to this problem.
Thank you very much for your effort.
You are like my right hand.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 290
Reputation: kv79 is an unknown quantity at this point 
Solved Threads: 7
kv79 kv79 is offline Offline
Posting Whiz in Training

Re: DLL and Application

 
0
  #12
Dec 21st, 2007
Hi,
Can anyone explain why do i need header( .h) and
( .c) for creating DLL in C?
When i usally open Dev-C++->project dll, i got 2 files 1 cdll.h and 1 cmain.c ,and whan i compile i got a project.dll .Few words woud be grathfull .
Thank you for your reading.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 290
Reputation: kv79 is an unknown quantity at this point 
Solved Threads: 7
kv79 kv79 is offline Offline
Posting Whiz in Training

Re: DLL and Application

 
0
  #13
Dec 21st, 2007
Hi ,
i discovered why did't work you and me with Dev-C++,because you and i have
Include linking wich it can't bedone in such small programs.
Project option->files->cdll.c
turn off include linking.But i findout it in the other turtorial http://www.apitalk.com/document.php?id=1184209001_1
Last edited by kv79; Dec 21st, 2007 at 6:57 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 290
Reputation: kv79 is an unknown quantity at this point 
Solved Threads: 7
kv79 kv79 is offline Offline
Posting Whiz in Training

Re: DLL and Application

 
0
  #14
Dec 21st, 2007
Hi, i created my dll and i call it myfile.dll
And i open Win32 clean project and put these files and it doesend work why?
  1. #include <windows.h>
  2.  
  3.  
  4.  
  5. typedef void (*function1_ptr) ();
  6.  
  7. function1_ptr function1=NULL;
  8.  
  9.  
  10.  
  11.  
  12.  
  13. int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
  14.  
  15.  
  16.  
  17. HMODULE myDll = LoadLibrary("myfile.dll");
  18.  
  19.  
  20.  
  21. if(myDll)
  22.  
  23. function1 = (function1_ptr) GetProcAddress(myDll,"function1");
  24.  
  25.  
  26.  
  27. if(function1)
  28.  
  29. function1();
  30.  
  31.  
  32.  
  33. FreeLibrary(myDll);
  34.  
  35.  
  36.  
  37. return 0;
  38.  
  39. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: DLL and Application

 
0
  #15
Dec 21st, 2007
What did not work ?

LoadLibrary
GetProcAddress
function1()
or
FreeLibrary ?

If LoadLibrary did not work, look in keep dll in the same folder of exe.
if GetProcAddress did not work
try dumpbin -exports <path>\myfile.dll in command prompt of visual studio to check if function1 is exported from the dll. Make sure you give right path of the dll.
if function1 did not work see your implimentation.
if FreeLibrary did not work, don't worry anyways yopu are ending your application.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 290
Reputation: kv79 is an unknown quantity at this point 
Solved Threads: 7
kv79 kv79 is offline Offline
Posting Whiz in Training

Re: DLL and Application

 
0
  #16
Dec 21st, 2007
Hi , i use Dev-C++
That file working but not right because he must put my MessageBox on the screen Here is myfile.dll
  1. #include <windows.h>
  2.  
  3. extern "C" {
  4.  
  5. //functions callable in dll
  6. void __declspec (dllexport) function1() {
  7. MessageBox (NULL, "test message","test title",0);
  8. }
  9.  
  10. }
  11.  
  12. BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID) {
  13. return TRUE;
  14. }

Thank you for your effort of reading.
Last edited by kv79; Dec 21st, 2007 at 11:25 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: DLL and Application

 
0
  #17
Dec 21st, 2007
I don't use LoadLibrary() for most DLLs that I write. Instead, I just use __dllimport and prototype it in the *.c or *.cpp application program, then link with the *.lib file that the compiler generated when the DLL was compiled and linked. But of course if you don't have a *.lib file then this method will not work.
  1. // prototype the function that is in the DLL
  2. void __declspec (dlimport) function1();
  3.  
  4. int main()
  5. {
  6. function1(); // call the function in the DLL
  7.  
  8. return 0;
  9. }
Last edited by Ancient Dragon; Dec 21st, 2007 at 12:00 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: DLL and Application

 
0
  #18
Dec 21st, 2007
There is should ne bo reason why MessageBox should fail provided you make that call and system is not running out of handles.

  1. int __declspec (dllexport) function1() {
  2. if(IDOK != MessageBox (NULL, "test message","test title",MB_OK))
  3. {
  4. DWORD dw = GetLastError();
  5. return dw;
  6. }
  7. return 0;
  8. }

change your implimentation as shown above and get the error code.
Last edited by dubeyprateek; Dec 21st, 2007 at 12:22 pm. Reason: adding MB_OK insted of IDOK
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 290
Reputation: kv79 is an unknown quantity at this point 
Solved Threads: 7
kv79 kv79 is offline Offline
Posting Whiz in Training

Re: DLL and Application

 
0
  #19
Dec 21st, 2007
What ever ,if you have a any file wich will explain to me what to do in ( .lib) .Please post it.
And if you know how to create ( .lib) plz post it here.
Thank you for your time.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: DLL and Application

 
0
  #20
Dec 21st, 2007
.lib is always created once you create a dll. You can include that .lib in linker options of your project then you dont need to call LoadLibrary. it is static linking of dll.
However, your implimentation is right if all the API calls are working and function() is exported(it is exported) you should see MessageBox.
Please change the implimentation and get me the error code.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Reply

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




Views: 2766 | Replies: 29
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC