View Full Version: Problem with D3D9.LIB

C++ Learning Community > Direct X > Problem with D3D9.LIB


Title: Problem with D3D9.LIB
Description: and BC++5.5


dr voodoo - November 2, 2003 06:05 PM (GMT)
I'm tring to create a simple DX9 Device. And I'm having problems to compile. Here's my code:
CODE
#include <windows.h>
#include <d3d9.h>
LRESULT WINAPI MsgProc(HWND, UINT, WPARAM, LPARAM);
//void Render(void);
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
   // Register the window class.
   WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                     hInst, NULL, NULL, NULL, NULL,
                     "D3D Tutorial", NULL };

   RegisterClassEx( &wc );

   // Create the application's window.
   HWND hwnd = CreateWindow( "D3D Tutorial",
                             "D3D Tutorial 01: CreateDevice",
                             WS_OVERLAPPEDWINDOW,
                             100, 100, 300, 300,
                             GetDesktopWindow(),
                             NULL,
                             hInst,
                             NULL );

   IDirect3D9* g_pD3D=Direct3DCreate9( D3D_SDK_VERSION );
   if(NULL==g_pD3D)
        return false;
       
   D3DPRESENT_PARAMETERS d3dpp;
   ZeroMemory( &d3dpp, sizeof(d3dpp) );
   d3dpp.Windowed = TRUE;
   d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
   d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
   
   IDirect3DDevice9*g_pd3dDevice;
   
   if(D3D_OK==g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,//default value
                                    D3DDEVTYPE_HAL,
                                    hwnd,
                                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                    &d3dpp,
                                    &g_pd3dDevice))
        return false;
         
   MSG msg;
   while( GetMessage( &msg, NULL, 0, 0 ) )
   {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
   }
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   switch( msg )
   {
       case WM_DESTROY:
           PostQuitMessage( 0 );
           return 0;

       case WM_PAINT:
           //Render();
           ValidateRect( hWnd, NULL );
           return 0;
   }

   return DefWindowProc( hWnd, msg, wParam, lParam );
}


And the linker returns this error:
QUOTE
Error: 'C:\BORLAND\BCC55\LIB\D3D9.LIB' contains invalid OMF record, type 0x21 (possibly COFF)

And I don't really know what that error means. Is there an error in my code which only shows at linkage or is the import lib corrupt?

dr voodoo - November 2, 2003 08:13 PM (GMT)
Ok I now got it to compile. I used implib.exe (batmaker>extended mode>get lib) to create a lib file based on the d3d9.dll.

But (after adding a ShowWindow function to the code above) when I execute it the window flashes and closes. Is that because of my code or because of my self made d3d9.lib?

TheHawgMaster - November 2, 2003 10:40 PM (GMT)
The only compiler that I have successfully compiled a DX9 application with is MSVC++6 Introductory. It's library format is different and doesn't work with the other compiler (MSVC++4 Std.) that I tried it with.

If this doesn't work. There is a problem with your lib.
CODE
#include <Windows.h>
#include <D3D9.h>
#include <D3DX9.h>

PASCAL WinMain(HINSTANCE ThisApp,
     HINSTANCE, LPSTR, INT)
{
WNDCLASS* W = new WNDCLASS;
memset(W, 0, sizeof(*W));
W->hInstance = ThisApp;
W->lpszClassName = "W";
W->lpfnWndProc = DefWindowProc;
RegisterClass(W);
delete W;
HWND Window = CreateWindowEx(WS_EX_TOPMOST, "W", "D3D9",
        WS_POPUP | WS_VISIBLE,
        0, 0,
        GetSystemMetrics(SM_CXSCREEN),
        GetSystemMetrics(SM_CYSCREEN),
        0, 0, ThisApp, 0);

IDirect3D9* Direct3D = Direct3DCreate9(D3D_SDK_VERSION);

D3DPRESENT_PARAMETERS d3dpp = {
 640, 480, D3DFMT_R5G6B5, 1, D3DMULTISAMPLE_NONE,
 0, D3DSWAPEFFECT_FLIP, Window, FALSE, FALSE,
 (D3DFORMAT)0, 0, D3DPRESENT_RATE_DEFAULT, D3DPRESENT_INTERVAL_DEFAULT };
IDirect3DDevice9* D3DDevice = 0;
Direct3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window,
        D3DCREATE_HARDWARE_VERTEXPROCESSING,
        &d3dpp, &D3DDevice);

HCURSOR PreviousCursor = SetCursor(0);

ID3DXMesh* Teapot = 0;
D3DXCreateTeapot(D3DDevice, &Teapot, 0);

MSG Msg;
while(GetAsyncKeyState(VK_END) ? 0 : 1)
{
 if(PeekMessage(&Msg, 0, 0, 0, PM_REMOVE))
 {
  TranslateMessage(&Msg);
  DispatchMessage(&Msg);
 }
 else
 {
  D3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 80, 255), 1.0f, 0);
  D3DDevice->BeginScene();

  Teapot->DrawSubset(0);

  D3DDevice->EndScene();
  D3DDevice->Present(0, 0, 0, 0);
 }
}

SetCursor(PreviousCursor);

if(Teapot)
 Teapot->Release();

if(D3DDevice)
 D3DDevice->Release();
if(Direct3D)
 Direct3D->Release();
return(Msg.wParam);
}

dr voodoo - November 3, 2003 03:59 PM (GMT)
I get the the folloeing error with your code:
QUOTE
Error E2268 C:\Borland\BCC55\Include\d3dx9math.inl 1515: Call to undefined function 'sqrtf' in function D3DXVec2Length(const D3DXVECTOR2 *)
Error E2268 C:\Borland\BCC55\Include\d3dx9math.inl 1647: Call to undefined function 'sqrtf' in function D3DXVec3Length(const D3DXVECTOR3 *)
Error E2268 C:\Borland\BCC55\Include\d3dx9math.inl 1792: Call to undefined function 'sqrtf' in function D3DXVec4Length(const D3DXVECTOR4 *)
Error E2268 C:\Borland\BCC55\Include\d3dx9math.inl 1962: Call to undefined function 'sqrtf' in function D3DXQuaternionLength(const D3DXQUATERNION *)
Warning W8010 C:\Borland\BCC55\Include\d3dx9core.h 485: Continuation character \ found in // comment
Warning W8010 C:\Borland\BCC55\Include\d3dx9core.h 486: Continuation character \ found in // comment
Warning W8010 C:\Borland\BCC55\Include\d3dx9core.h 487: Continuation character \ found in // comment
Warning W8010 C:\Borland\BCC55\Include\d3dx9core.h 488: Continuation character \ found in // comment
Warning W8010 C:\Borland\BCC55\Include\d3dx9core.h 489: Continuation character \ found in // comment

And don't even get to the linkage part.

Do you perhaps know what is different with VC++ 6 libs or did MS only do it to make older compilers incompatible?

TheHawgMaster - November 3, 2003 06:28 PM (GMT)
You can fix the sqrtf errors (or indeed any errors from math functions ending with 'f') by the obvious:
CODE
inline float sqrtf(float f)
 {return(sqrt((double)f));}

dr voodoo - November 3, 2003 06:52 PM (GMT)
QUOTE
You can fix the sqrtf errors (or indeed any errors from math functions ending with 'f') by the obvious:
CODE
inline float sqrtf(float f)
{return(sqrt((double)f));}

Is that some sort of function that only exists with VC++? Anyway thanks for telling me. If I now somewhere can find a list with all the DX9 dlls, the libs will probably not be any problem.

EDIT:Do you know in which dll the D3DXCreateTeapot function is?

TheHawgMaster - November 3, 2003 07:59 PM (GMT)
QUOTE
Is that some sort of function that only exists with VC++?
Doesn't exist in VC++4 either... But does work in VC++6. I don't think it's ANSI.

And I suppose D3DXCreateTeapot would be in d3dx9.dll or d3dx9d.dll

btw that code won't draw a teapot. It will draw a black square :lol:

dr voodoo - November 3, 2003 09:05 PM (GMT)
QUOTE
And I suppose D3DXCreateTeapot would be in d3dx9.dll or d3dx9d.dll

Are sure about that?

Because I can't either find a d3dx9.dll nor a d3dx9d.dll in the system32 dir. :blink:
The closest I could find is d3dxof.dll and it's not in there.

I tried to compile without the teapot part and it works. That is it goes into fullscreen mode and the screen becomes a light blue. I can exit it by pushing end. It's eating up all CPU power and the screen resolution changes to (I think) 640x480.

Is that what's supposed to happen?

QUOTE
Doesn't exist in VC++4 either... But does work in VC++6. I don't think it's ANSI.

Definatly not.

TheHawgMaster - November 4, 2003 12:03 AM (GMT)
QUOTE
Because I can't either find a d3dx9.dll nor a d3dx9d.dll in the system32 dir.
That's because they're in the system dir, not the system32 dir.

QUOTE
it goes into fullscreen mode and the screen becomes a light blue. I can exit it by pushing end. It's eating up all CPU power and the screen resolution changes to (I think) 640x480.

Is that what's supposed to happen?
Exactly. (Correction: sky blue (j/k))

MonkeyMan - November 4, 2003 01:27 AM (GMT)
Hehe... just if you want to know... its eating all the power because it is constantly being redrawn in the while loop. As posted in another message... there is the option of making ur own WndProc and using lilke WM_TIMER and SetTimer(hwnd,1,50,NULL); to make it only redraw every 50ms... just a thought but i am not realy sure about direct x as i havent got into it yet.

TheHawgMaster - November 4, 2003 04:15 AM (GMT)
That would work fine MonkeyMan. I just did that that way because full-screen D3D application usually don't even try to multi-task.

dr voodoo - November 4, 2003 12:32 PM (GMT)
QUOTE
That's because they're in the system dir, not the system32 dir.

I don't have a file called d3dx9.dll nor d3dx9d.dll anywhere :unsure:

QUOTE
Exactly. (Correction: sky blue (j/k))

So it's working :)




* Hosted for free by InvisionFree