locked
Get Video Memory with DirectX RRS feed

  • Question

  • Well, hello. I'm working on a System to get Video Available Memory. The problem is that for example if i do:

    	DXGI_ADAPTER_DESC AdapterDescription;
    	Adapters[AdapterNum]->GetDesc(&AdapterDescription);
    	string Desc = toString(AdapterDescription.Description);
    	static char AdapterDesc[255];
    	memset(AdapterDesc, 0x00, 255);
    	memcpy(AdapterDesc, Desc.c_str(), Desc.size());
    	return AdapterDesc;
    
    string toString (type val) {
    	stringstream s;
    	s << val;
    	return s.str();
    }

    Returns strange chars. (Such as 0012E1F0) when i want it to return the Description.

     

    And yeah, you may know why i'm passing it to char *. It's a long story. :/

     

    Any idea of how to fix this?

    Saturday, February 19, 2011 8:44 AM

Answers

  • On 19/02/2011 09:44, Kazuma5 wrote:

    Well, hello. I'm working on a System to get Video Available Memory. The problem is that for example if i do:

    [code]
        DXGI_ADAPTER_DESC AdapterDescription;
        Adapters[AdapterNum]->GetDesc(&AdapterDescription);

    I'd suggest you step with the debugger and check that AdapterDescription is written properly by the GetDesc method above.
     >     string Desc = toString(AdapterDescription.Description);

    The Description string is made by WCHAR's, and you want to convert to std::string. What encoding are you using with std::string? UTF-8? Some local code page?
    If you don't use UTF-8, this conversion can be lossy.

    If you want to convert from Unicode UTF-16 (WCHAR) to some ANSI/MBCS string, you can use ATL helpers like CW2A.
     You may want to use

        static char AdapterDesc[255];
        memset(AdapterDesc, 0x00, 255);
        memcpy(AdapterDesc, Desc.c_str(), Desc.size());
        return AdapterDesc;

    Assuming that you are going to copy from a std::string to this local static buffer, you could simply use strcpy_s:

    strcpy_s( AdapterDesc, Desc.c_str() );
     Giovanni

    • Marked as answer by Yi Feng Li Tuesday, March 1, 2011 3:47 AM
    Saturday, February 19, 2011 9:52 AM

All replies

  • On 19/02/2011 09:44, Kazuma5 wrote:

    Well, hello. I'm working on a System to get Video Available Memory. The problem is that for example if i do:

    [code]
        DXGI_ADAPTER_DESC AdapterDescription;
        Adapters[AdapterNum]->GetDesc(&AdapterDescription);

    I'd suggest you step with the debugger and check that AdapterDescription is written properly by the GetDesc method above.
     >     string Desc = toString(AdapterDescription.Description);

    The Description string is made by WCHAR's, and you want to convert to std::string. What encoding are you using with std::string? UTF-8? Some local code page?
    If you don't use UTF-8, this conversion can be lossy.

    If you want to convert from Unicode UTF-16 (WCHAR) to some ANSI/MBCS string, you can use ATL helpers like CW2A.
     You may want to use

        static char AdapterDesc[255];
        memset(AdapterDesc, 0x00, 255);
        memcpy(AdapterDesc, Desc.c_str(), Desc.size());
        return AdapterDesc;

    Assuming that you are going to copy from a std::string to this local static buffer, you could simply use strcpy_s:

    strcpy_s( AdapterDesc, Desc.c_str() );
     Giovanni

    • Marked as answer by Yi Feng Li Tuesday, March 1, 2011 3:47 AM
    Saturday, February 19, 2011 9:52 AM
  • Well. Seems that wcstombs() did the work fine. :P

     

    But how i make it return only video Desc? :P

    Saturday, February 19, 2011 8:16 PM
  • On 19/02/2011 21:16, Kazuma5 wrote:


    But how i make it return only video Desc? :P

    I'd suggest to just return a std::wstring (Unicode) with the video description.

    Why do you want to return a raw C char*?

    Can't you use C++?

    Giovanni

    Saturday, February 19, 2011 9:51 PM
  • No i meant, i don't want it to show / GeForce 630a (or it was 640, idk)

     

    jsut Nvidia GeForce 7025

    Sunday, February 20, 2011 3:47 AM
  • Hi Kazuma5,

     

    The DXGI_ADAPTER_DESC structure provides a description of an adapter. The major issue about above code is converting from WCHAR* to char*. For more information about converting between various string types, please check http://msdn.microsoft.com/en-us/library/ms235631.aspx. If the string of adapter description is not what you excepted, you may contact adapt vendor for more information.

     

    Since the title of the thread is about the video memory, you can obtain the dedicated video memory, dedicated system memory  and shared system memory from the corresponding member of DXGI_ADAPTER_DESC Structure.  

     

    Since it is a DirectX related issue, for your future concern about DirectX functions, please visit our XNA forums: http://forums.create.msdn.com/forums/

     

    Cheers,

    Yi

     

     


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 22, 2011 6:52 AM