2010-12-06 30 views
0

我有一個使用VS2008的C++/CLI庫構建,它使用marshal_as將System :: String方法參數轉換爲std :: string類型以傳入本機指針的方法參數。代碼看起來與此非常相似:字符串參數沒有通過發佈模式

System::Void QueryContext::SetNamespace(String^ prefix, String^ uri) 
{ 
    std::string _prefix; 
    if (nullptr != prefix) 
    { 
    _prefix = marshal_as<std::string>(prefix); 
    } 
    std::string _ns; 
    if (nullptr != uri) 
    { 
    _ns = marshal_as<std::string>(uri); 
    } 
    // at this point both variables are confirmed to have values 
    // at least from within the Locals view in the debugger 
    _ctx->setNamespace(_prefix,_ns); 
} 

此代碼正在爲x64平臺編譯。

我目前遇到的問題是:當代碼在調試模式下構建時,它運行時沒有任何問題。當代碼以Release模式構建時,本機指針(_ctx)會引發異常,基本上說沒有賦值給變量_ns,儘管我已經能夠在調試器中確認該值確實存在。

換句話說,本機代碼在調試模式下運行良好,但在發佈模式下,它失敗了,因爲值在本機代碼中顯示爲空白。

在發佈模式或marshal_as模板中是否存在導致問題的事情?有沒有人遇到過這種問題?

謝謝!

+0

你有兩個潛在的漏洞。你能確保`prefix`和`uri`總是作爲'nullptr`以外的值傳遞嗎? – MrGomez 2010-12-06 04:52:47

回答

0

原來,在C++ - >代碼生成設置中,發佈庫已鏈接到多線程調試 DLL(/ MDd),與項目設置中正確的多線程DLL(/ MD) 。

相關問題