Accessing Video Memory Information...need help

This is a discussion on Accessing Video Memory Information...need help within the C++ Programming forums, part of the General Programming Boards category; Okay, I was going to write a program for fun (and maybe, probably not practical use) that sees how much ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    42

    Accessing Video Memory Information...need help

    Okay, I was going to write a program for fun (and maybe, probably not practical use) that sees how much Video Memory you have, and how much your using. My friend sugessted DirectDraw for this task.

    I googled video memory programming, and came up with this link. The first answer says this:

    ...
    IDirectDraw7::GetCaps

    dwVidMemTotal
    Total amount of display memory on the device, in bytes, minus memory reserved for the primary surface and any private data structures reserved by the driver. (This value is the same as the total video memory reported by the IDirectDraw7::GetAvailableVidMem method.)
    dwVidMemFree
    Free display memory. This value equals the value in dwVidMemTotal, minus any memory currently allocated by the application for surfaces. Unlike the GetAvailableVidMem method, which reports the memory available for a particular type of surface (such as a texture), this value reflects the memory available for any type of surface.
    ...
    From what I've read you need ddraw.h and ddraw.dll (both of which I have).
    From MSDN (*dodges flames*) it says that IDirectDrawVideo::GetCaps (HRESULT GetCaps(DDCAPS *pCaps);) can get this information also.

    Now, onto my question. Should I use one of these two methods or possibly another one? And is there a good DirectDraw tutorial that teaches use of one of the methods?

    I found this. Good tutorial, but it doesn't teach GetCaps or dwVidMemTotal/dwVidMemFree. If someone could point me in the right direction, I would be most grateful.

    Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    It looks like a good options is to just use the method:

    Code:
    IDirectDraw7::GetAvailableVidMem( LPDDSCAPS2 lpDDSCaps2, ... )
    Just call your GetCaps function to fill in that first parameter. Then pointers to dwords for the last 2 params. The second param is the total memory and the third is amount of free memory.

    Do you need help initializing the DirectDraw object? What exactly is the problem here.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    42
    Okay so IDirectDraw7?

    Well on initializing it, this says to put in the given code. But when I do, it spits out all these errors at me. I've included ddraw.dll (in my project, not as a header file ) and ddraw.h, but it doesn't seem to be enough.

    And how exactly would I use GetCaps to fill lpDDSCaps2?
    Sigh, nothing ever works the first try.

    Register Linux User #314127

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    42
    A single bump doesn't hurt.
    Sigh, nothing ever works the first try.

    Register Linux User #314127

  5. #5
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    This is probably the wrong board. You should ask confuted or post in the game dev board.

    As far as I know, you can't use the DirectX DLLs directly. You need to use those functions through the "interface". No clue how it's done in C. In Delphi they had those nifty TInterface thingys....

    Anyway, try this board if nobody know a reply here.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by KneeLess
    Okay so IDirectDraw7?

    Well on initializing it, this says to put in the given code. But when I do, it spits out all these errors at me. I've included ddraw.dll (in my project, not as a header file ) and ddraw.h, but it doesn't seem to be enough.

    And how exactly would I use GetCaps to fill lpDDSCaps2?
    Well what exactly are the errors? Either post the code or attach a zip and I'll take a look at it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    42
    Code:
    #include "stdafx.h"
    #include <ddraw.h>
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    	// Initialize DirectDraw
    	LPDIRECTDRAW7 lpDD7;
    	HRESULT hr;
    	
    	if (FAILED(hr = DirectDrawCreateEx(NULL, (VOID**)&lpDD7, IID_IDirectDraw7, NULL)))
    		return FALSE;
    	
    	if (FAILED(hr = lpDD7->SetCooperativeLevel(NULL, DDSCL_NORMAL)))
    		return FALSE;
    	
    	return 0;
    }
    Errors:
    C:\c\DirectDrawTest2\DirectDrawTest2.cpp(13) : error C2065: 'LPDIRECTDRAW7' : undeclared identifier
    C:\c\DirectDrawTest2\DirectDrawTest2.cpp(13) : error C2146: syntax error : missing ';' before identifier 'lpDD7'
    C:\c\DirectDrawTest2\DirectDrawTest2.cpp(13) : error C2065: 'lpDD7' : undeclared identifier
    C:\c\DirectDrawTest2\DirectDrawTest2.cpp(16) : error C2065: 'DirectDrawCreateEx' : undeclared identifier
    C:\c\DirectDrawTest2\DirectDrawTest2.cpp(16) : error C2065: 'IID_IDirectDraw7' : undeclared identifier
    C:\c\DirectDrawTest2\DirectDrawTest2.cpp(19) : error C2227: left of '->SetCooperativeLevel' must point to class/struct/union
    Error executing cl.exe.

    ...help?

    (Thanks so far MrWizard)
    Sigh, nothing ever works the first try.

    Register Linux User #314127

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Looks like you aren't linking to the correct libraries.

    Link to the ddraw.lib and dxguid.lib

    If you don't know how consult your compiler documentation.
    If you are using Visual Studio you can do

    Code:
    #pragma comment(lib,"ddraw.lib")
    #pragma comment(lib,"dxguid.lib")
    This won't work on other compilers though.

    Try that and it will probably fix it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    42
    Added those after the headers on VC++6, didn't work, same errors.
    Sigh, nothing ever works the first try.

    Register Linux User #314127

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you write directly into video memory in windows vista?
    By kypronite in forum Game Programming
    Replies: 3
    Last Post: 08-02-2008, 03:12 PM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. Linked Lists
    By bigblack in forum C++ Programming
    Replies: 7
    Last Post: 02-05-2002, 05:21 PM
  4. accessing Memory location
    By a_learner in forum C Programming
    Replies: 6
    Last Post: 10-10-2001, 03:16 PM
  5. accessing more than 64k of video memory
    By stupid_mutt in forum C Programming
    Replies: 1
    Last Post: 10-03-2001, 03:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21