通過clr封裝c++介面時Marshal::PtrToStructure()封送到托管物件double型別屬性值出錯。
void OnRspSubscribeQuote( const TapAPIQuoteWhole *info)
{
//先從const轉 非const
TapAPIQuoteWhole *t = const_cast<TapAPIQuoteWhole *>(info);
//創建一個托管物件
TapQuoteWhole^ field = gcnew TapQuoteWhole();
//封送非托管資料到托管物件
Marshal::PtrToStructure(IntPtr(t), field);
//通過除錯看了,托管物件中:field->QPreClosingPrice = -438866786677+76
//
// 非托管結構中:t->QPreClosingPrice = 2430;
}
總結:通過Marshal::PtrToStructure封送到托管物件的double,long這種資料型別數值不對。但是string型別的屬性是對的。
uj5u.com熱心網友回復:
沒人回答,我自己答,是因為雙方結構位元組排列方式不對稱問題,pack=1 同步排序方式就行了轉載請註明出處,本文鏈接:https://www.uj5u.com/net/89047.html
標籤:C#
