如何从非托管代码(从Smalltalk应用程序)调用Webservice或c#dll [英] How to call Webservice or c# dll from unmanaged code (from Smalltalk application)

查看:156
本文介绍了如何从非托管代码(从Smalltalk应用程序)调用Webservice或c#dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个旧的VSE Smalltalk应用程序,我们希望能够调用将返回字符串的c#Web服务.

我一直无法从Smalltalk获得对托管dll的任何调用,但是我已经能够创建可以从Smalltalk调用的c ++ win32 dll,而后者又可以调用c#托管代码.

有谁知道不通过c ++就可以直接使c#调用正常工作的任何其他选项(例如,构建dll的方法?).我们在使用有限的c ++知识映射字符串时遇到问题,如果可能的话,我们真的想绕过这一层.

请注意,smalltalk应用程序是一个独立的应用程序(exe及其sll文件),它没有像其他Windows应用程序那样安装,并且是在.NET诞生之前编写的.

谢谢
UKJohn

We have an old VSE Smalltalk application and we want to be able to call a c# webservice that will return a string.

I have been unable to get any call to a managed dll working from Smalltalk but I have been able to create a c++ win32 dll that can be called from Smalltalk, which in turn can call c# managed code.

Does anyone know of any other options for getting the c# call working directly without going through the c++ (eg ways to build the dll?). We are running into issues mapping strings with our limited c++ knowledge and would really like to bypass this layer if possible.

Note the smalltalk app is a standalone app (exe and its sll files), it is not installed like other windows apps and was written way before the birth of .NET

Thanks
UKJohn

推荐答案

是的,我基本上知道Smalltalk是如何工作的.如果您可以加载常规的非托管DLL并调用某些导出的函数,则使用.NET程序集进行加载就足够了,但这一点都不容易.我不想讨论COM组件的实现方式,我正在考虑将某些.NET方法导出为非托管方法的功能.

许多开发人员甚至会说这绝对是不可能的,但事实并非如此:有一种基于CLR标准的解决方案,而不是基于纯C#的解决方案.

诀窍是构建一个C#项目,将其分解为IL代码,对其进行修改以使某些方法导出为非托管形式并重新编译.另外,还有一种自动的方法:用某些属性标记这些方法,并在特殊的MSBuild任务中实施其他所有操作.这样,您可以将这样的自定义构建集成到您的纯C#项目中.

如果仍然有兴趣,请先阅读我有关此解决方案的答案:
在MFC中加载C#DLL [如何使用在Visual Basic 6.0中的Visual Basic 2008中创建的dll [从Unmanged Code VC ++用C#调用托管DLL [ ^ ],
.a中的 API:托管或非托管代码 [ ^ ].

您将找到对CodeProject文章的更多参考,包括源代码和详细说明.

—SA
Yes, I basically know how Smalltalk works. If you can load a regular unmanaged DLL and call some of exported function, it would be enough to load use a .NET assembly, but this is not easy at all. I don''t want to discuss a way of implementation of COM component, I''m taking about the ability to export some .NET methods as unmanaged.

Many developers would even say this is absolutely impossible, but this is not true: there is a solution based on CLR standard, but not on pure C#.

The trick is to build a C# project, disassemble it into IL code, modify it to make some methods exported as unmanaged and compile back. Also, there is an automated way to do it: mark those method with some attribute and implement everything else in a special MSBuild task. This way, you can integrate such customized build into your pure-C# project.

If still interested, please first read my answers about this solution:
loading C# DLL in MFC[^],
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
API''s in .Net: Managed or UnManaged Code[^].

You will find further references to CodeProject articles with source code and detailed explanation.

—SA


这篇关于如何从非托管代码(从Smalltalk应用程序)调用Webservice或c#dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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