2013-12-16 150 views
0

大家好,感謝您花時間看我的問題。 我有這個節目,我想提出的運行過程中出現錯誤,我已經把範圍縮小到1升當我構建std :: string時,爲什麼會出現這個R6030錯誤?

std::string str(id.Description, (sizeof(id.Description)/sizeof(id.Description[0]))); 

下面是完整的功能

bool isItNvidia() 
{ 
    IDirect3D9* pD3D9 = NULL; 
    pD3D9 = Direct3DCreate9(D3D_SDK_VERSION); 
    if(pD3D9) 
    { 
    UINT dwAdapterCount = pD3D9->GetAdapterCount(); 
    for(UINT iAdapter = 0; iAdapter < dwAdapterCount; iAdapter++) 
    { 
     D3DADAPTER_IDENTIFIER9 id; 
     ZeroMemory(&id, sizeof(D3DADAPTER_IDENTIFIER9)); 
     pD3D9->GetAdapterIdentifier(iAdapter, 0, &id); 

    //std::cout<< id.Description<<std::endl; 
    /* 
    wchar_t wtext[MAX_DEVICE_IDENTIFIER_STRING]; 
    std::mbstowcs(wtext, id.Description, strlen(id.Description)+1); 
    LPWSTR ptr = wtext; 
    MessageBox(NULL, ptr, L"nigg", MB_OK); 
    */ 

     std::string str(id.Description, (sizeof(id.Description)/sizeof(id.Description[0]))); 
     std::string comp="NVIDIA"; 


     if(str.find(comp) != std::string::npos) 
     { 
      return true; 
      Beep(300, 500); 
     } 


    } 
} 
return false; 

pD3D9->Release(); 
delete pD3D9; 
} 

您還需要在D3D9。 h和d3d9.lib文件。

我不知道它爲什麼這樣做 的id.Description是一個字符數組

如果有人可以幫助我將不勝感激。 感謝

+0

'Description'的類型爲char [MAX_DEVICE_IDENTIFIER_STRING]',因此不需要指定它的大小。 – Raxvan

+1

函數在return語句後沒有被執行,所以你有一些相當重要的不可達代碼。我會建議在追蹤其他錯誤之前解決這個問題。 –

+0

感謝您的答案,但奇怪的是,這與配置鏈接器的入口點有關。當我評論說,線條雖然工作。 – user2837329

回答

0

由於C運行時(CRT)未正確初始化,您會收到錯誤消息。請參閱此處瞭解可能的問題原因: http://msdn.microsoft.com/en-us/library/9ecfyw6c.aspx

+0

你的回答是最有幫助的,我最終改變了鏈接器上的入口點,並且它工作正常。 – user2837329

+0

@ user2837329我很高興我的回答對你有幫助!請將答案標記爲「已接受」。在這裏你可以得到一個想法如何標記它:[http://stackoverflow.com/tour](http://stackoverflow.com/tour) –

8

只是初始化字符串std::string str(id.Description);

說明:

此構造可能會稱爲,這是不是你想要的:

basic_string(const basic_string& other, 
      size_type pos, 
      size_type count = std::basic_string::npos, 
      const Allocator& alloc = Allocator()); 

pos參數將導致垃圾地址。

相關問題