我有第三方.dll,我必須在C++/CLI代碼中使用它的函數。我想dllimport的,但我收到一個錯誤:Dllimport函數返回結構
錯誤C33385:「msp_FormatMessage」:具有dllimport的定製attribite不能返回類
的一個實例,在C#中這個問題可以通過解決的功能使用StructLayout,但我找不到在C++/CLI中解決此問題的任何方法。
函數定義:
[DllImport("drtl3.dll", EntryPoint = "msp_FormatMessage")]
extern "C++" msp_Message msp_FormatMessage(msp_Message* buffer, char type, char RT, char SA, char RTR_MC, unsigned short SAR_MCD, char dataWordCount, unsigned short data[], unsigned int bccw);
結構定義:
typedef struct {
msp_WORD type;
msp_WORD dataWordCount;
msp_WORD bccw;
msp_WORD CmdWord1;
msp_WORD CmdWord2;
msp_WORD Data[32];
msp_WORD StatusWord1;
msp_WORD StatusWord2;
msp_WORD loopback;
msp_WORD bsw;
msp_WORD timetag;
msp_BYTE present;
msp_BYTE transmit;
msp_BYTE check;
msp_BYTE role;
} msp_Message;
您應該標記'C++/CLI'這樣的問題,很多環視'C++'標籤的人甚至不知道它存在,所以在詢問時應該明確說明它 – PeterT 2014-12-04 00:28:37
您確定結果是直接返回而不是指針? – svick 2014-12-05 01:27:55
[我能找到的唯一'msp_FormatMessage](http://www.module.ru/upload/files/2604_rtl2gsw.pdf#page=47)確實如此:'msp_Message * msp_FormatMessage( msp_Message * buffer, msp_BYTE類型, msp_BYTE RT, msp_BYTE SA, msp_BYTE RTR_MC, msp_WORD SAR_MCD, msp_BYTE dataWordCount, msp_WORD *數據, msp_DWORD bccw);' – svick 2014-12-05 01:34:29