Thread: "is not a member of 'IDirect3D9'" error

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    2

    "is not a member of 'IDirect3D9'" error

    Hello

    i the past few weeks i have build up some basic knowledg about c and c++, and so i got myself the book "beginning game programming"
    and from that book i tried to compile a code with visual studio .net 2003. i got the following errors:

    Code:
     : error C2039: 'CreateDevice' : is not a member of 'IDirect3D9'
     : error C2039: 'Clear' : is not a member of 'IDirect3DDevice9'
     : error C2039: 'BeginScene' : is not a member of 'IDirect3DDevice9'
     : error C2039: 'EndScene' : is not a member of 'IDirect3DDevice9'
     : error C2039: 'Present' : is not a member of 'IDirect3DDevice9'
     : error C2039: 'Release' : is not a member of 'IDirect3DDevice9'
     : error C2039: 'Release' : is not a member of 'IDirect3D9'
    This is my code(complete "program"):

    Code:
    //------------------------------------------
    //Fireup a basic d3d window
    //reference: beginning game programming
    //------------------------------------------
    
    //Headers
    #include <windows.h>
    #include <d3d9.h>
    #include <time.h>
    
    //Application Title
    #define APPTITLE "Fire up Direct-X"
    
    //Forward declarations( prototypes )
    LRESULT WINAPI WinProc(HWND,UINT,WPARAM,LPARAM);
    ATOM MyRegisterClass(HINSTANCE);
    //own Funtions
    int  App_Init  (HWND);
    void App_Run   (HWND);
    void App_Close (HWND);
    
    //Global Variables (d3d)
    LPDIRECT3D9 d3d = NULL;
    LPDIRECT3DDEVICE9 d3ddev = NULL;
    D3DPRESENT_PARAMETERS d3dpp;
    
    
    ////////////////////WINDOWS(window) FUNCTIONS/////////////////////////
    //window event callback function
    LRESULT WINAPI Winproc (HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
    
    {
    	switch(msg)
    	{
    	case WM_DESTROY:
    		App_Close(hWnd);
    		PostQuitMessage(0);
    		return 0;
    	}
    	return DefWindowProc(hWnd,msg,wParam,lParam);
    }
    //window properties
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    	//create window class (properties)structure
    	WNDCLASSEX wc;
    	wc.cbSize = sizeof(WNDCLASSEX);
    
    	//fill the structure (define properties)
    	wc.style         = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc   = (WNDPROC)WinProc;
    	wc.cbClsExtra    = 0;
    	wc.cbWndExtra    = 0;
    	wc.hInstance     = hInstance;
    	wc.hIcon		 = NULL;
    	wc.hCursor		 = LoadCursor(NULL,IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = APPTITLE;
    	wc.hIconSm		 = NULL;
    	
    	//set up the window with the info
    	return RegisterClassEx(&wc);
    }
    
    //Entry point for a Windows program (actual APP launch)
    int WINAPI WinMain(HINSTANCE hInstance,
    				   HINSTANCE hPrevInstance,
    				   LPSTR	 lpCmdLine,
    				   int		 nCmdShow)
    {
    	//Declare function variables
    	MSG msg;
    	HWND hWnd;
        int done = 0;
    
    	//register the class
    	MyRegisterClass(hInstance);
    
    	//Create the base window
    	hWnd = CreateWindow(
    		APPTITLE,
    		APPTITLE,
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		500,
    		400,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
    
    	//check for an error during creation
    	if (!hWnd)
    		return FALSE;
    	//actually display the window
    	ShowWindow(hWnd, nCmdShow);
    	UpdateWindow(hWnd);
    
    	//Initialize this app (App_Init)
    	if (!App_Init(hWnd))
    		return 0;
    
    	//////THIS IS THE LOOP/////
    	
    	while (!done)
    	{
    		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    		{
    			//react when quit message comes by
    			if (msg.message == WM_QUIT)
    			{
    				//dispay an exit message
    				MessageBox(hWnd,"Received WM_QUIT message", "WinMain",MB_OK);
    				done = 1;
    			}
    
    			//decode and send message over to WndProc
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    		else
    			//THE APP LOOP(in else to preven keep running after closing
    			App_Run(hWnd);
    	}
    	return (int)msg.wParam;
    }
    //end
    ////////////////////END OF WINDOWS FUNCTIONS/////////////////////////
    
    ////////////////////Continue With DirectX///////////////////////////
    //App_init function
    int App_Init(HWND hWnd)
    {
    	//Declare some vars
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
    	
    	//display an init message
    	MessageBox(hWnd,"Program is about to start!!","Game_Init",MB_OK);
    
    	//initialize DIRECT 3D
    	if (d3d == NULL)
    	{
    		MessageBox(hWnd,"Error at initialize D3D","Error App_Init",MB_OK);
    		return 0;
    	}
    	//Set D3Dpp ,vica vi directx options of the App
    	ZeroMemory(&d3dpp,sizeof(d3dpp));
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    
    	//create the d3d device
    	d3d->CreateDevice(
    		D3DADAPTER_DEFAULT,
    		D3DDEVTYPE_HAL,
    		hWnd,
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    		&d3dpp,
    		&d3ddev);
    
    	if(d3ddev == NULL)
    	{
    		MessageBox(hWnd,"Error creating D3D Device","error d3d device",MB_OK);
    		return 0;
    	}
    
    	//random number seed (WHY??)
    	//srand(time(NULL));
    
    	//i saw it was good
    	return 1;
    }
    
    //App_Run function
    void App_Run(HWND hwnd)
    {
    	//make sure the d3ddev is valid
    	if(d3ddev == NULL)
    		return;
    
    	//Clear the backbuffer with white
    	d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,255),1.0f,0);
    
    	/////START THE RENDER////ILL BE BACK HERE
    	if (d3ddev->BeginScene())
    	{
    		//DO STUFF
    		
    		//STOP STUFF
    		d3ddev->EndScene();
    	}
    
    	//Display the backbuffer (display something)
    	d3ddev->Present(NULL,NULL,NULL,NULL);
    }
    
    		
    //App_Close function
    void App_Close(HWND hWnd)
    {
    	//display close message
    	MessageBox(hWnd,"Program is about to end","Game_End",MB_OK);
    
    	//Release the d3ddev and d3d
    
    	if(d3ddev != NULL)
    		d3ddev->Release();
    	if(d3d != NULL)
    		d3d->Release();
    }
    //end
    /////////////////////END OF OWN(DIRECTX)FUNCTIONS//////////

    i dont understand caue the the members is just there. if i look in d3d9.h is see such line:


    typedef struct IDirect3D9 *LPDIRECT3D9, *PDIRECT3D9;
    .....
    #define IDirect3D9_CreateDevice(p,a,b,c,d,e,f) (p)->CreateDevice(a,b,c,d,e,f)
    ....

    Thanks in advance.

    btw. if this is a noob question please tell me.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I suggest that when your coding for DirectX, you use C++, at least to start with. However, you can call a COM interface, such as IDirect3D9, from C. It is done like this:
    Code:
    	//Clear the backbuffer with white
    	d3ddev->lpVtbl->Clear(d3ddev, 0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255  ,255),1.0f,0);
    
    	/////START THE RENDER////ILL BE BACK HERE
    	if (d3ddev->lpVtbl->BeginScene(d3ddev))
    You should have noticed the addition of lpVtbl and the passing of the object pointer as the first argument. The must be done for each COM call in C.

    Alternatively, you can use the C object macros. This involves adding #define COBJMACROS above all your includes and calling COM interfaces like this:
    Code:
    IDirect3D9_Clear(d3ddev,0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,255),1.0f,0)
    IDirect3D9_BeginScene(d3ddev);
    Last edited by anonytmouse; 07-03-2005 at 05:50 AM. Reason: Typo: lpVtbl not lpVtlb. Whoops

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    2
    Thanks a lot, i didnt noticed the ! in

    Code:
    #if !defined(__cplusplus) || defined(CINTERFACE)
    thank you for your input and btw it is

    lpVtbl not lpVtlb

    again thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  4. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM