Jump to content
  • Advertisement
Sign in to follow this  
pdform

Problems with C and COM

This topic is 4447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, there... I'm new here, so be patient... I'm working in a project with C and DirectX. Before you say that, I know that Cpp is a really better choice to work with DirectX but I actually prefer C and I'd like to learn how to work with DirectX in that language. My problem is that, tough I can run Direct3D, I simply couldn't access the member functions to set the scene and render. I believe the problem is the way I'm working with COM. Here goes the code I created to test Direct3D bulding a simple blue window (only the funtions that initialize and set DirectX) and the errors I received from VC++6. If you can help me, please, do that...
line 99 here
//----------------------------------------------------------------------------- 
 // Desc: Inicializa o Direct3D 
 //----------------------------------------------------------------------------- 
 HRESULT InitD3D( HWND hWnd ) 
 { 
    // Estrutura usada para criar o dispositivo 
     D3DPRESENT_PARAMETERS d3dpp; 
 
     // Cria o objeto Direct3D 
     if(NULL==(g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) 
         return E_FAIL; 
     
    //inicializa biblioteca COM 
    hr = CoInitialize(NULL); 
 
    if (FAILED(hr)) 
       return E_FAIL; 
 
    //configura opções de inicialização 
     ZeroMemory( &d3dpp, sizeof(d3dpp) ); 
     d3dpp.Windowed = TRUE; 
     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; 
     d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; 
     d3dpp.EnableAutoDepthStencil = TRUE; 
     d3dpp.AutoDepthStencilFormat = D3DFMT_D16; 
 
     
    //Cria o Device 
    hr = IDirect3D9_CreateDevice(g_pD3D, 0, D3DDEVTYPE_HAL, hWnd, 
                              0, &d3dpp, &g_pd3dDevice); 
 
 
     if( FAILED(hr)) 
         return E_FAIL; 
 
     return S_OK; 
 } 
 
 //----------------------------------------------------------------------------- 
 // Nome: Cleanup() 
 //----------------------------------------------------------------------------- 
 void Cleanup() 
 { 
     if( g_pd3dDevice != NULL ) 
       IDirect3DDevice9_Release(g_pd3dDevice); 
     
     if( g_pD3D != NULL )        
         IDirect3D9_Release(g_pD3D); 
 
    //fecha a biblioteca COM 
    CoUninitialize(); 
 } 
 
 //----------------------------------------------------------------------------- 
 // Nome: Render() 
 //----------------------------------------------------------------------------- 
 void AdjustStates() 
 { 
    //matriz de projeção 
    D3DXMATRIX matProj; 
        
     //Desliga a oclusão automática de faces 
     hr = g_pd3dDevice -> lpVtbl-> SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE ); 
 
     //Desliga a iluminação da cena 
     hr = g_pd3dDevice -> lpVtbl-> SetRenderState( D3DRS_LIGHTING, FALSE ); 
     
    //zbuffer ligado 
     hr = g_pd3dDevice -> lpVtbl-> SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); 
 
     //Ajusta a matriz de projeção 
     D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.5f, 1.0f, 100.0f ); 
     hr = g_pd3dDevice -> lpVtbl-> SetTransform( D3DTS_PROJECTION, &matProj ); 
 } 
 
 //----------------------------------------------------------------------------- 
 // Nome: Render() 
 //----------------------------------------------------------------------------- 
 void Render() 
 { 
     // Limpa backbuffer pintando-o de azul 
     hr = g_pd3dDevice -> lpVtbl-> Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                          D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); 
 
     // Inicia a cena 
     if( SUCCEEDED( hr = g_pd3dDevice -> lpVtbl-> BeginScene() ) ) 
     { 
         // Encerra a cena 
         hr = g_pd3dDevice -> lpVtbl-> EndScene(); 
     } 
 
     // Apresenta o conteúdo do backbuffer (mostra o que foi desenhado) 
     hr = g_pd3dDevice -> lpVtbl-> Present( NULL, NULL, NULL, NULL ); 
 } 
\main.c(162) : warning C4047: 'function' : 'struct IDirect3DDevice9 *' differs in levels of indirection from 'int ' \main.c(162) : warning C4024: 'function through pointer' : different types for formal and actual parameter 1 \main.c(162) : error C2198: 'function through pointer' : too few actual parameters \main.c(165) : warning C4047: 'function' : 'struct IDirect3DDevice9 *' differs in levels of indirection from 'int ' \main.c(165) : warning C4024: 'function through pointer' : different types for formal and actual parameter 1 \main.c(165) : error C2198: 'function through pointer' : too few actual parameters \main.c(168) : warning C4047: 'function' : 'struct IDirect3DDevice9 *' differs in levels of indirection from 'int ' \main.c(168) : warning C4024: 'function through pointer' : different types for formal and actual parameter 1 \main.c(168) : error C2198: 'function through pointer' : too few actual parameters \main.c(172) : warning C4047: 'function' : 'struct IDirect3DDevice9 *' differs in levels of indirection from 'int ' \main.c(172) : warning C4024: 'function through pointer' : different types for formal and actual parameter 1 \main.c(172) : warning C4047: 'function' : 'int ' differs in levels of indirection from 'struct _D3DMATRIX *' \main.c(172) : warning C4024: 'function through pointer' : different types for formal and actual parameter 2 \main.c(172) : error C2198: 'function through pointer' : too few actual parameters \main.c(181) : warning C4047: 'function' : 'unsigned long ' differs in levels of indirection from 'void *' \main.c(181) : warning C4024: 'function through pointer' : different types for formal and actual parameter 2 \main.c(181) : warning C4047: 'function' : 'const struct _D3DRECT *' differs in levels of indirection from 'const long ' \main.c(181) : warning C4024: 'function through pointer' : different types for formal and actual parameter 3 \main.c(182) : warning C4244: 'function' : conversion from 'const float ' to 'unsigned long ', possible loss of data \main.c(182) : error C2198: 'function through pointer' : too few actual parameters \main.c(185) : error C2198: 'function through pointer' : too few actual parameters \main.c(188) : error C2198: 'function through pointer' : too few actual parameters \main.c(192) : error C2198: 'function through pointer' : too few actual parameters

Share this post


Link to post
Share on other sites
Advertisement
Correct me if I am wrong but I thought using the COM interfaces in C, you have to pass the pointer to the object you are calling a function of in AGAIN as the first parameter to the function, to simulate the this pointer implicitly there in C++.

g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice);

If this is correct, it would explain why all your errors are "Not enough parameters."

Not too sure about this though.

Share this post


Link to post
Share on other sites
Thank you, guys.

But the fact is that I had never worked explicitaly with COM before this project so I had no idea of that. I'm gonna test. Thanks again.

Share this post


Link to post
Share on other sites
Quote:
Original post by Demirug
No need to correct you, as you are absolute right.


I hereby declare today a national holiday [grin].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!