2016-03-15 54 views
1

我很困难,并且一直在搜索相当长的一段时间。 我打电话一个C++ DLL从C# 我可以把一切工作正常,在一个简单的控制台应用程序,但相同的代码不会在Web应用程序的工作Web应用程序中的Dllimport System.StackOverflowException控制台工作正常

我使用Windows 10 64位,但我不得不一切使用32位和呼叫是CDECL

C#代码:

namespace WebApp 
{ 
    public class LibWrap 
    { 
    [DllImport("mdll.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)] 
    public static extern Int32 MySize(Int64 start, 
     Int32 count, 
     Int64[] from, 
     Int64[] to, 
     Int32[] ids, 
     ref Int32 id_cnt); 
    } 

    public partial class Default : System.Web.UI.Page 
    { 
     protected void Button1_Click(object sender, EventArgs e) 
     { 
      Int64 l_start = 1431644400; 
      Int64[] l_from = { 
           1431644400, 
           1432114200, 
           1432162800, 
           1432278000, 
           1432335600 
          }; 
      Int64[] l_to = { 
           1431673200, 
           1432119600, 
           1432200600, 
           1432288800, 
           1432364400 
          }; 
      Int32[] l_IDs = { 
           1, 
           1, 
           1, 
           1, 
           1 
          }; 
      int l_idCnt = 0; 
      Int32 l_Count = LibWrap.MySize(l_start, l_from.Length, l_from, l_to, l_IDs, ref l_idCnt); 
     } 
    } 
} 

的DLL标题代码被称为是:

#define DEF_EXPORT __declspec(dllexport) __cdecl 

int32_t DEF_EXPORT MySize(int64_t start, 
          int32_t count, 
          int64_t * from, 
          int64_t * to, 
          int32_t * ids, 
          int32_t & id_cnt); 

C++源:

int32_t DEF_EXPORT MySize(int64_t start, 
          int32_t count, 
          int64_t * from, 
          int64_t * to, 
          int32_t * ids, 
          int32_t & id_cnt) 
{ 
    MyCore mycore; 

    int32_t sz = 0; 

    if (count) 
    { 
    mycore.Count = count; 

    mycore.Ids = ids; 
    mycore.From = from; 
    mycore.To  = to; 

    mycore.Start = start; 

    IDList id_positions[MY_LIMIT]; 
    id_cnt = 1; 

    sz = mycore.OutputSize(id_positions, id_cnt); 

    } 
    return sz; 
} 

正如我所说的试图调用MySize Web应用程序时抛出一个System.StackOverflowException错误。 只要我输入MySize函数(即在第一行运行之前)就使用本机代码调试System.StackOverflowException 感谢任何见解,我在网上找到的每个解决方案似乎已经在我的案例中被覆盖。

+1

出于好奇,如果你将MySize方法存储(仅立即返回0),会发生什么? – Rob

+0

@Rob值得一试。 – Irshad

+0

在你的C++代码中是否有任何可疑的递归调用? – Irshad

回答

0

好吧,这是一个堆栈内存提供给控制台应用程序与webapps的问题 在32位下,Web应用程序只能获得256Kb。

罪魁祸首是数组:

IDList id_positions[MY_LIMIT]; 

移动这一个动态分配得到它出栈和解决的问题。

相关问题