使用dll时出现问题 [英] Issues working with a dll

查看:187
本文介绍了使用dll时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我一直试图让一个dll工作一段时间,尤其是一个用于计算占星位置的

.

最后几天前有了一个要编译的程序,在dll中获取"get_planet_name"方法的输出以给出实际响应.  
当我尝试从dll测试另一种方法时,我收到一条错误消息,但耸了耸肩,因为,嘿,程序终于可以正常工作了,有时间修补一下,以后再让它工作(所以我没有认为要记录特定的详细信息/代码 不.当时的错误).

如下代码(以及属性->生成"中选中的允许不安全代码"框):

静态课程Program {
    [STAThread]
    [DllImport("swedll32.dll")]公共静态不安全外部字符串swe_get_planet_name(int ipl,字符串plname);
    [DllImport("swedll32.dll")]公共静态不安全外部长swe_calc(双tjd_et,int ipl,长iflag,双xx,字符串serr);

    静态void Main(){
        System.Diagnostics.Debug.WriteLine(swe_get_planet_name(0,"a")));
        System.Diagnostics.Debug.WriteLine(swe_calc(2457659,0,0,0,")));
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(新Form1());
    }
} 


第二天回到它并在启动时测试编译,它再次崩溃,这次甚至不再运行'get_planet_name'方法,并且没有在Visual Studio中显示错误对话框-它只是关闭了测试程序最后一行 在输出"面板中说:

程序'[5796] DLL_Tester.vshost.exe'已退出,代码-1073740940(0xc0000374)."
快速谷歌建议的是托管堆损坏的例外;尝试在关闭不安全模式的情况下重新编译它,并从这两种方法中删除了不安全",但仍然崩溃,并带有相同的错误代码.

我充其量只是C#的中级知识,所以我不知道如何解决堆问题(如果这是真正的问题所在).  有什么建议吗?
(如果相关的话:在Windows 10 Home v1607中使用Visual Studio Community 2015 v4.6.01586)

谢谢!

解决方案

从我在文档中看到的内容来看,这已经很老了,运气不佳上班.我不会花很多时间,尤其是当作者只有一个实际地址而没有电子邮件地址时.

另请参阅第18节及以下.

http://www.astro.com/swisseph/swephprg.htm#_Toc452449225


Hi all,

I've been trying to get a dll working for a while, specifically one to calculate astrological positions.

Finally got a program to compile a few days ago, getting the output of the 'get_planet_name' method in the dll to give an actual response.  
When I tried testing another method from the dll, I got an error message but shrugged my shoulders because, hey, the program was finally sort-of working, there'd be time to tinker and get it working later (so I didn't think to record the specific details/code no. of the error at the time).

Code as follows (as well as the 'allow unsafe code' box checked in Properties -> Build):

static class Program {
    [STAThread]
    [DllImport("swedll32.dll")] public static unsafe extern string swe_get_planet_name(int ipl, string plname);
    [DllImport("swedll32.dll")] public static unsafe extern long swe_calc(double tjd_et, int ipl, long iflag, double xx, string serr);

    static void Main() {
        System.Diagnostics.Debug.WriteLine(swe_get_planet_name(0, "a"));
        System.Diagnostics.Debug.WriteLine(swe_calc(2457659, 0, 0, 0, ""));
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());            
    }
}


Coming back to it the next day and testing the compile on startup, it crashed again, this time no longer even running the 'get_planet_name' method, and not bringing up the error dialog in Visual Studio - it simply closed the test program and the last line in the Output panel said:

"The program '[5796] DLL_Tester.vshost.exe' has exited with code -1073740940 (0xc0000374)."
which a quick google suggests is the exception for a corrupting in the managed heap; tried recompiling it with unsafe mode turned off and removing the 'unsafe' from both methods, but it still crashed with the same error code.

I'm at best an intermediate with c#, so I've no idea how to fix a heap issue (if that's where the true problem is).  Any suggestions?
(In case it's relevant: using Visual Studio Community 2015 v4.6.01586 in Windows 10 Home v1607)

Thanks!

解决方案

From what I've seen in the documentation this is fairly old and may be out of luck getting things to work. I would not put a lot of time into this especially when the author only has a physical address, no email address.

See also section 18 and below.

http://www.astro.com/swisseph/swephprg.htm#_Toc452449225


这篇关于使用dll时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆