如何修复使用Delphi / C#这样的非托管的出口困境 [英] How to fix this unmanaged exports trouble using Delphi/C#
本文介绍了如何修复使用Delphi / C#这样的非托管的出口困境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I came across Unmanaged exports technique in this anwser on SO.
- 我可以管理自己有简单的项目工作 SharpDevelop的的,虽然我不知道有C#的一个很好的命令。
- 我想用优秀的 Gavaghan.Geodesy (.NET / C#)库写麦克Gavaghan。
- 我想避免的互操作性,通过COM。
- 我肯定用Delphi。我只是想利用图书馆吧。
- I can manage myself to have simplest project working on SharpDevelop, albeit I don't have a good command of C#.
- I want to use the excellent Gavaghan.Geodesy (.Net/C#) library written by Mike Gavaghan.
- I want to avoid interoperability through COM.
- I definitely use Delphi. I only want to harness the library with it.
我设法建立以下code:
I managed to build the following code :
using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
namespace DelphiNET
{
internal static class UnmanagedExports
{
[DllExport("add", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static int add(int left, int right) {
return left + right;
}
}
}
我探讨其与德尔福,但是是徒劳的。
I probed it with Delphi but was in vain.
我检查了输出的dll用PE编辑器,但它原来没有出口数据都没有。
I checked the output dll with a PE editor but It turned out to have no export data at all.
我想念的东西,我很困惑。
I miss something and I'm confused.
编辑:
请 - 帮助我解决麻烦
Please - Help me fix the trouble
推荐答案
我设法得到这个工作是这样的:
I managed to get this to work like this:
- 下载C#项目<一href="https://sites.google.com/site/robertgiesecke/Home/uploads/csharpprojecttemplateforunmanagedexports"相对=nofollow>模板。这需要Visual Studio,但你应该罚款以EX preSS版本。
- 创建一个新的项目基于模板。
- 在构建一个项目。
- 在加载DLL的Dependency Walker中看到,它确实导出功能。我成功地调用德尔福的功能。
- Download the C# Project template. This requires Visual Studio but you should be fine with the Express version.
- Create a new project based on the template.
- Build that project.
- Load the DLL in Dependency Walker to see that it does indeed export the function. I succeeded in calling the function from Delphi.
请注意,为了查找DLL路径是斌\调试\ 86
。有一个在 A DLL斌\调试
但这并没有出口。也许,这就是你一直在寻找。
Note that the path to find the DLL is bin\Debug\x86
. There is a DLL in bin\Debug
but this has no exports. Perhaps that's what you have been looking at.
这篇关于如何修复使用Delphi / C#这样的非托管的出口困境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文