2013年5月20日月曜日

【C#】動的に(C/C++)のDllを読み込む際に、「PInvokeStackImbalance が検出されました」と出る件について

元のソース

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate int xxx(ushort wMode,uint dwLon, uint dwLat, ushort wLevel, ushort wFlg);



int ret = 0;
            xxx drawMap = (xxx)Marshal.GetDelegateForFunctionPointer(funcAddressDrawMap, typeof(xxx));
            ret = drawMap((ushort)p, (uint)dwLon, (uint)dwLat, (ushort)wLevel, (ushort)p_2);
            return ret;

だと、「PInvokeStackImbalance が検出されました」とうざいメッセージが表示される。
で、いろいろ調べた結果
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
→[UnmanagedFunctionPointer(CallingConvention.Winapi)]
に変えたら出なくなった。
なぜなのかはこれから調べる。