Problem while using function from loaded dll

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

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

Problem while using function from loaded dll

 
0
  #1
Mar 25th, 2009
O.k guys the reason for the new thread because no one understood the previous thread even I didn't understand what I wrote lol!

Now listen to my problem.

I wrote an exe file that loads a dll and than uses a function from inside of the dll!

BUT!! my exe crashes while in runtime!! (runtime error)

Here is my exe code
  1. /*Typedef the hello function*/
  2. typedef void (*pfunc)();
  3.  
  4. /*Windows handle*/
  5. HINSTANCE HandleDLL;
  6.  
  7. /*A pointer to a function*/
  8. pfunc hello;
  9.  
  10. /*LoadLibrary*/
  11. HandleDLL = LoadLibrary("message.dll");
  12. if (HandleDLL != 0)
  13. printf("MESSAGE library loaded!\n");
  14. else
  15. printf("MESSAGE library failed to load!\n");
  16.  
  17. /*GetProcAddress*/
  18. hello = (pfunc)GetProcAddress(HandleDLL,"hello");
  19.  
  20. /*Call the function*/
  21. hello();

I think that the problem comes when I am calling the hello function..

Anyone has any ideas how to solve it??

Here is my dll source for more info

  1. #if BUILDING_DLL
  2. # define DLLIMPORT __declspec (dllexport)
  3. #else /* Not BUILDING_DLL */
  4. # define DLLIMPORT __declspec (dllimport)
  5. #endif /* Not BUILDING_DLL */
  6.  
  7. DLLIMPORT void hello()
  8. {
  9. MessageBox (0, "Hello from injected DLL!\n", "Hi", MB_ICONINFORMATION);
  10. }

help anyone??

It should work!!!

please help!!
Reply With Quote Quick reply to this message  
Reply

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




Views: 240 | Replies: 0
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC