2012-03-22 81 views
1

我有一個C#的COM對象wtitten,我在C++ dll中使用它。c#COM對象&「ESP的值沒有正確地保存在一個函數調用...」

C++中的COM對象導入與#import derective

的問題是,當呼叫從一個C++ DLL作出了COM對象的任何功能,我得到一個運行時檢查錯誤:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

在用C++導入指令產生的COM對象的包裝,所有函數聲明爲__stdcall

+0

可能重複http://stackoverflow.com/questions/4104774/the-value- of-esp-was-not-saved-properly) – 2012-03-22 11:08:00

+1

這是COM調用非常不尋常的問題,調用約定和參數類型都是機器生成的。您需要更好地描述代碼,至少需要發佈C#聲明和C++調用的片段。簡單的解釋是你使用的是舊版本的類型庫。 – 2012-03-22 11:14:45

+0

它看起來像我找到了解決方案: i'v declated In/Out/MarshalAs屬性的所有方法和參數在C#COM – ili 2012-03-22 11:38:45

回答

1

OK,它看起來像我已經找到了解決辦法: 我已經declated在輸入/輸出/的MarshalAs屬性在C#COM接口的所有方法:

[Guid("EEB4C1AE-4DB2-4bdb-86D4-A429B27496A3")] 
public interface IAXFarCards 
{ 
    [DispId(1)] 
    void InitDbConnection([In, MarshalAs(UnmanagedType.BStr)] string connectionString); 

    [DispId(2)] 
    [return: MarshalAs(UnmanagedType.I4)] 
    int GetCardInfo(
     [In, MarshalAs(UnmanagedType.BStr)]    string card, 
     [In, MarshalAs(UnmanagedType.VariantBool)]  bool isTemplate, 
     [In, MarshalAs(UnmanagedType.I4)]    int cashDeskId, 
     [Out, MarshalAs(UnmanagedType.VariantBool)] out bool isActive, 
     [Out, MarshalAs(UnmanagedType.I4)]   out int discountNumber, 
     [Out, MarshalAs(UnmanagedType.I8)]   out Int64 amount, 
     [In, Out, MarshalAs(UnmanagedType.BStr)] ref string ownerName, 
     [In, Out, MarshalAs(UnmanagedType.I4)]  ref int clientId 
     ); 
的[未正確保存的ESP的值](
相關問題