943,713 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 326
  • C++ RSS
Mar 25th, 2009
0

Problem while using function from loaded dll

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  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

C++ Syntax (Toggle Plain Text)
  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!!
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
laconstantine is offline Offline
70 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Waiting till another exe file finishes
Next Thread in C++ Forum Timeline: Number Sorting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC