Can't use a DLL inside my executable

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 69
Reputation: laconstantine is an unknown quantity at this point 
Solved Threads: 1
laconstantine laconstantine is offline Offline
Junior Poster in Training

Can't use a DLL inside my executable

 
0
  #1
Mar 25th, 2009
OK so I got my executable file that should load all the functions from
"message.dll" so I can use them.

But every time I run my executable file I am getting an error that say my executable is encountered problems and its should be closed than its being closed.

Here is my executable source

  1.  
  2.  
  3. #include <windows.h>
  4. #include <stdio.h>
  5.  
  6. int main () {
  7.  
  8. /*Typedef the hello function*/
  9. typedef void (*pfunc)();
  10.  
  11. /*Windows handle*/
  12. HINSTANCE HandleDLL;
  13.  
  14. /*A pointer to a function*/
  15. pfunc hello;
  16.  
  17. /*LoadLibrary*/
  18. HandleDLL = LoadLibrary("message.dll");
  19.  
  20. /*GetProcAddress*/
  21. hello = (pfunc)GetProcAddress(HandleDLL,"hello");
  22.  
  23. /*Call the function*/
  24. hello();
  25. return 0;
  26. }

And this is what the hello function suppose to do
source from the dll

  1. __declspec(dllexport) void hello()
  2.  
  3. {
  4. MessageBox (0, "Hello from injected DLL!\n", "Hi", MB_ICONINFORMATION);
  5. }
Any ideas why my exe crashes when I run it?
Last edited by laconstantine; Mar 25th, 2009 at 6:09 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 69
Reputation: laconstantine is an unknown quantity at this point 
Solved Threads: 1
laconstantine laconstantine is offline Offline
Junior Poster in Training

Re: Can't use a DLL inside my executable

 
0
  #2
Mar 25th, 2009
Listen guys i just discovered that the problem comes when I try to use the hello function from the dll.


any ideas?? please?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC