-1

I want to dynamically load the client dll in my C++ Windows application. So I am using ACE_DLL. I want to create the object of the class in client dll in my application . So I have written a wrapper class. One of its member function creates the object of ACE_DLL. Then using that object I am loading the client dll. Next I am calling the symbol function through ACE_DLL object and passing the mangled name of constructor of the class in client dll. Next I am calling the function pointer (_entry ) which contains address of the constructor but this time I am getting error as "Unhandled exception (Access violation)"

Please let me know if my approach is correct. Below are the calling sequence in my application.


ACE_DLL* _pDll; typedef Test* (*TestFP)(); TestFP _entry;


_pDll = new ACE_DLL();

_pDll->open("dllname_to_be_opend");

std::string sSymbol = "Test"; // mangled name of the Test class constructor in client dll

_entry = (TestFP) _pDll->symbol(sSymbol.c_str());

Test *obj = _entry(); // Unhandled exception at 0x00362b2f in Testdll.exe: 0xC0000005: Access violation writing location 0x00362b0c.


Thank you, Prasad

Prasad B
  • 1
  • 2

2 Answers2

1

That looks about right. Can you run ACE_wrappers/tests/DLL_Test.exe? If that works then compare the test code to yours more closely.

Steve Huston
  • 1,432
  • 13
  • 20
  • No. My Test application is not running. Giving the error as Unhandled exception. I am confused if, I can get the address of the Test class constructor in client dll using symbol() method and then call this function pointer to create the object of Test class. – Prasad B Jan 12 '17 at 07:36
  • If the test program isn't running either, it's most likely a build problem. I recommend comparing your build setup to one on the build scoreboard (http://www.dre.vanderbilt.edu/scoreboard/) that most closely matches your environment and see what's different. Once you can get the DLL_Test working, go back and re-try your program. – Steve Huston Jan 16 '17 at 17:11
0

The code you have presented i.e.

_pDll = new ACE_DLL();
_pDll->open("dllname_to_be_opend");
std::string sSymbol = "Test"; 
_entry =  (TestFP) _pDll->symbol(sSymbol.c_str());

does not verify that the return value of ACE_DLL::open call is zero (0 for success, -1 on failure) or that the return value of ACE_DLL::symbol call is not zero (0 is returned on failure).

J.J. Hakala
  • 6,136
  • 6
  • 27
  • 61