@allen
刚才有简单测试了下, 测试代码如下:
D3DPRESENT_PARAMETERS ps = {0};
ps.Windowed = TRUE;
ps.SwapEffect = D3DSWAPEFFECT_DISCARD;
ps.BackBufferFormat = D3DFMT_UNKNOWN;
pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL
, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &ps, &g_pD3dDevice);
if(g_pD3dDevice == NULL) break;
LPDIRECT3DDEVICE9 pNewD3dDevice = NULL;
pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL
, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &ps, &pNewD3dDevice);
创建了2个IDirect3DDevice9对象, 然后分别打印它们的虚表指针和内容:
0:000> ?? g_pD3dDevice
struct IDirect3DDevice9 * 0x02815c00
+0x000 __VFN_table : 0x0281899c
0:000> ?? pNewD3dDevice
struct IDirect3DDevice9 * 0x0241bfe0
+0x000 __VFN_table : 0x0241ed7c
0:000> dps 0x0281899c
0281899c 6fe56f19 d3d9!CBaseDevice::QueryInterface
028189a0 6fe56992 d3d9!CBaseDevice::AddRef
028189a4 6fe56969 d3d9!CBaseDevice::Release
028189a8 6fe72587 d3d9!CBaseDevice::TestCooperativeLevel
028189ac 6ff0c6ad d3d9!CBaseDevice::GetAvailableTextureMem
028189b0 6ff49c8f d3d9!CD3DBase::EvictManagedResources
028189b4 6fe6b1c5 d3d9!CBaseDevice::GetDirect3D
028189b8 6fe56ff8 d3d9!CBaseDevice::GetDeviceCaps
028189bc 6fe8d144 d3d9!CBaseDevice::GetDisplayMode
028189c0 6fe7084e d3d9!CBaseDevice::GetCreationParameters
028189c4 6ff0bb74 d3d9!CBaseDevice::SetCursorProperties
028189c8 6ff0c04d d3d9!CBaseDevice::SetCursorPosition
028189cc 6fe8def0 d3d9!CBaseDevice::ShowCursor
028189d0 6fe6e9a0 d3d9!CBaseDevice::CreateAdditionalSwapChain
028189d4 6fe69ac7 d3d9!CBaseDevice::GetSwapChain
028189d8 6fe993ca d3d9!CBaseDevice::GetNumberOfSwapChains
028189dc 6feaf251 d3d9!CBaseDevice::Reset
028189e0 6fe9a064 d3d9!CBaseDevice::Present
028189e4 6feb1418 d3d9!CBaseDevice::GetBackBuffer
028189e8 6fe6bfe9 d3d9!CBaseDevice::GetRasterStatus
028189ec 6ff0c139 d3d9!CBaseDevice::SetDialogBoxMode
028189f0 6ff0c3bf d3d9!CBaseDevice::SetGammaRamp
028189f4 6ff0c4fd d3d9!CBaseDevice::GetGammaRamp
028189f8 6fe85ddb d3d9!CBaseDevice::CreateTexture
028189fc 6ff0ca68 d3d9!CBaseDevice::CreateVolumeTexture
02818a00 6feacb2d d3d9!CBaseDevice::CreateCubeTexture
02818a04 6fe72d69 d3d9!CBaseDevice::CreateVertexBuffer
02818a08 6fe732e6 d3d9!CBaseDevice::CreateIndexBuffer
02818a0c 6fea0127 d3d9!CBaseDevice::CreateRenderTarget
02818a10 6ff0cd88 d3d9!CBaseDevice::CreateDepthStencilSurface
02818a14 6ff0e0e0 d3d9!CBaseDevice::UpdateSurface
02818a18 6fe846ab d3d9!CBaseDevice::UpdateTexture
0:000> dps 0x0241ed7c
0241ed7c 6fe56f19 d3d9!CBaseDevice::QueryInterface
0241ed80 6fe56992 d3d9!CBaseDevice::AddRef
0241ed84 6fe56969 d3d9!CBaseDevice::Release
0241ed88 6fe72587 d3d9!CBaseDevice::TestCooperativeLevel
0241ed8c 6ff0c6ad d3d9!CBaseDevice::GetAvailableTextureMem
0241ed90 6ff49c8f d3d9!CD3DBase::EvictManagedResources
0241ed94 6fe6b1c5 d3d9!CBaseDevice::GetDirect3D
0241ed98 6fe56ff8 d3d9!CBaseDevice::GetDeviceCaps
0241ed9c 6fe8d144 d3d9!CBaseDevice::GetDisplayMode
0241eda0 6fe7084e d3d9!CBaseDevice::GetCreationParameters
0241eda4 6ff0bb74 d3d9!CBaseDevice::SetCursorProperties
0241eda8 6ff0c04d d3d9!CBaseDevice::SetCursorPosition
0241edac 6fe8def0 d3d9!CBaseDevice::ShowCursor
0241edb0 6fe6e9a0 d3d9!CBaseDevice::CreateAdditionalSwapChain
0241edb4 6fe69ac7 d3d9!CBaseDevice::GetSwapChain
0241edb8 6fe993ca d3d9!CBaseDevice::GetNumberOfSwapChains
0241edbc 6feaf251 d3d9!CBaseDevice::Reset
0241edc0 6fe9a064 d3d9!CBaseDevice::Present
0241edc4 6feb1418 d3d9!CBaseDevice::GetBackBuffer
0241edc8 6fe6bfe9 d3d9!CBaseDevice::GetRasterStatus
0241edcc 6ff0c139 d3d9!CBaseDevice::SetDialogBoxMode
0241edd0 6ff0c3bf d3d9!CBaseDevice::SetGammaRamp
0241edd4 6ff0c4fd d3d9!CBaseDevice::GetGammaRamp
0241edd8 6fe85ddb d3d9!CBaseDevice::CreateTexture
0241eddc 6ff0ca68 d3d9!CBaseDevice::CreateVolumeTexture
0241ede0 6feacb2d d3d9!CBaseDevice::CreateCubeTexture
0241ede4 6fe72d69 d3d9!CBaseDevice::CreateVertexBuffer
0241ede8 6fe732e6 d3d9!CBaseDevice::CreateIndexBuffer
0241edec 6fea0127 d3d9!CBaseDevice::CreateRenderTarget
0241edf0 6ff0cd88 d3d9!CBaseDevice::CreateDepthStencilSurface
0241edf4 6ff0e0e0 d3d9!CBaseDevice::UpdateSurface
0241edf8 6fe846ab d3d9!CBaseDevice::UpdateTexture
可以看到g_pD3dDevice的虚表地址是0x0281899c, pNewD3dDevice的虚表地址是0x0241ed7c,他们各自拥有自己虚表,尽管虚表里的内容是一样。如果你改变第一个对象的虚表内容,理论上不会影响第二个对象。
回复 更多评论