0

Possible Duplicate:
Calling private method in C++

I have a DLL, and in that DLL they exposed some functions but one of them is private. The function is C_MORPHO_Device::InitUsbDevicesNameEnum(PUL o_pul_NbUsbDevice).

How can I call this InitUsbDevicesNameEnum function in my application?

Community
  • 1
  • 1
WallPoster
  • 52
  • 1
  • 7

4 Answers4

3

Simply do not do that. The library author has made the function private, so you shall not call it. Read the documentation to find out which functions you are intended to call.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

Private method should be private to others. Why you need to call a private method, if the made at as private ?. They have made like this for some reason.

You can check any of other public or friend function in that calling this method InitUsbDevicesNameEnum. But that is not a good way of accessing private methods

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Sahal
  • 4,046
  • 15
  • 42
  • 68
0

There isn't a direct way to instantiate the class and call its private method.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Manmohan Singh
  • 439
  • 1
  • 3
  • 15
0

Is the private method also exported? I doubt it (why would they export a private method?). But if it is exported, you can use the dumpbin /exports command to see the decorated method name, then use GetProcAddress to get a function pointer to the method and call on an instance of the class. Something like:

HMODULE hModule = LoadLibrary(L"thedll.dll");
(C_MORPHO_Device::*pMethod)(PUL) = reinterpret_cast<(C_MORPHO_Device::*)(PUL)>(GetProcAddress(hModule, L"InitUsbDevicesNameEnum@_ABunchOfSymbolsHere"));

C_MORPHO_Device device;
(device.*pMethod)(...);
user1610015
  • 6,561
  • 2
  • 15
  • 18