开发者

c++ virtual function . surprising result application using VTABLE of some other dll having same architecture just name difference

i m creating a dll called "box.dll" . inside this i m calling a function showBox() . this function is decalred in another dll library called Stack.lib ( class Stack). inside this library i have declared this function (showBox() ) as virtual in Stack class. stack class is a derived class of BASE stack class having same function (showBox() ) (vtable machenisim). while compiling the Box.dll it is compiling without linking from stack.lib. i.e. i am able to compile box.dll without linking from stack.lib. linker is not giving an error.

i have create another dll called Bstack.dll having same function like stack.lib . i.e. i just copied开发者_运维技巧 the code of stack.lib and rename it to BStack.lib.

i have created a console base c++ application , inside that i m gona use Box library. for running my c++ application i need to give Box.dll and stack.dll.

but the main trap is my application is running without stack.dll. when i removed stack.dll and used BStack.dll it is working fine. how it is possible.

because the dependency of Box.dll is stack.dll not BStack.dll. but both have same architecture.

is this possible. plz reply if any clarification is required.


No, it is not possible. If Box.dll depends on and uses showBox from stack.dll then Box.dll needs stack.dll in order to function properly.

There are several possibilities why it works:

  1. box.dll does not really depend on stack.dll and has its own showBox() implementation
  2. box.dll depends on stack.dll and your console app depends on box.dll. when starting the console app stack.dll (on which box.dll depends) is found and used (i.e. it is in the directory where the console applications is, or you have copied it in C:\Windows\system32).

Some tools to help diagnose your problem:

Dependency Walker - you can use it to open box.dll and see on what modules it really depends

Process Explorer - you can select the console application and see all loaded dlls

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜