我想创建一个可以从非托管代码(Delphi 5)访问的.NET程序集.
我找到了Unmanaged Exports并按照那里的步骤进行了操作但是我甚至无法成功编译基本示例:
using RGiesecke.DllExport; namespace DelphiNET { public class Class1 { [DllExport("add")] public static int Add(int left,int right) { return left + right; } } }
DelphiNET.csproj项目文件:
... <ItemGroup> <Compile Include="Class1.cs" /> <Compile Include="DllExport\DllExportAttribute.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="DllExport\RGiesecke.DllExport.targets" /> ...
这是错误:
------ Build started: Project: DelphiNET,Configuration: Release Any cpu ------ c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\DelphiNET.dll /target:library Class1.cs DllExport\DllExportAttribute.cs Properties\AssemblyInfo.cs Compile complete -- 0 errors,0 warnings DelphiNET -> C:\DelphiNET\bin\Release\DelphiNET.dll ILDasm: calling 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe' with /quoteallnames /nobar "/out:C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.il" "C:\DelphiNET\bin\Release\DelphiNET.dll" C:\DelphiNET\bin\Release\DelphiNET.dll : warning EXP0009: Platform is Anycpu,generating creating binaries for each cpu platform in a separate folder... ILAsm: calling 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ILAsm.exe' with /nologo "/out:C:\DelphiNET\bin\Release\x86\DelphiNET.dll" "C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.x86.il" /DLL "/resource=C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.res" /optimize C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembling 'C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.x86.il' to DLL --> 'C:\DelphiNET\bin\Release\x86\DelphiNET.dll' C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Source file is ANSI C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::.ctor C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::get_CallingConvention C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::set_CallingConvention C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::get_ExportName C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::set_ExportName C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : ***** FAILURE ***** C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Done building project "DelphiNET.csproj" -- Failed. ========== Build: 0 succeeded or up-to-date,1 Failed,0 skipped ==========
操作系统:WinXPSP3,带有SP1的Microsoft Visual C#2008 Express Edition,.NET 3.5 SP1
知道什么是错的吗?谢谢.
编辑23:40:
解决方法
顺便说一下,我刚刚更新了档案.
当你拿走 this时,你甚至可以为你准备好这一切.
当你拿走 this时,你甚至可以为你准备好这一切.
这是一个项目模板,可以设置一切,应该可以正常工作.
我确实在之前的版本中找到了一些要点,我做了一些并非总是如此的假设.我之前实现的一个潜在问题是/ optimize开关,它用于发布配置.在这种情况下,有时ILAsm会扼杀IL,我没有看到新版本.