创建外部功能 [英] Create external functions

查看:102
本文介绍了创建外部功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我们有一个旧的C ++应用程序创建一个exe,我们的实验室窗口可以调用此exe函数.这个C ++应用程序太旧了,我们想再次用C#重写.如何在C#中创建外部函数来替代C ++函数,以便我们的主实验室窗口应用程序可以调用?

谢谢,

Trammy

Hello,

We have an old C++ app creating an exe where our lab window can call this exe functions. This C++ app is so old, and we would like to rewrite again in C#. How can I create external functions in C# to substitute C++ functions so our main lab window application can call?

Thanks,

Trammy

推荐答案

目前尚不清楚您想要做什么.您有要从C#调用函数的C ++ exe吗?如果您具有C ++ DLL,则可以p/调用C#中的函数.

当然,您可以编写一个执行与C ++应用程序相同的功能的C#exe.我不确定您所说的外部功能"是什么. C ++ exe不会将函数导出到外界(据我所知).这就是DLL的目的.

编辑...有一个灯泡的时刻.您是说您的C ++ exe充当服务器或服务,而您的实验室应用程序通过TCP或命名管道或其他类型的进程间通信向其发送命令? C#完全支持该类型的通信.

在考虑了这一点之后,我可以肯定地确定您想要做的是创建一个C#应用程序,该程序将进程间通信(IPC)统一起来与您的实验室应用程序进行通信.使用.NET TCP类非常简单.我没有在.NET中使用命名管道的个人经验,但我想它们可能也很容易.当然比C ++同行要容易.

[
It''s not very clear what it is that you want to do. You have a C++ exe that you want to call functions in from C#? If you have a C++ DLL you can p/invoke the functions in C#.

Sure you can write a C# exe that performs the same functionality that your C++ app does. I am not sure what you mean by "external functions". C++ exe do not export functions to the outside world (to the best of my knowledge). That is what DLLs are for.

Edit... having a lightbulb moment. Do you mean that your C++ exe acts as a server or service and your lab application sends commands to it via TCP or named pipes or other type of interprocess communication? C# fully supports that type of communication.

After thinking about this I am fairly certain that what you are wanting to do is create a C# application that unitizes inter-process communication (IPC) to communicate with your lab application. This is fairly simple to do using the .NET TCP classes. I have no personal experience using the named pipes with .NET but I would imagine that they are probably pretty easy too. Certainly easier than the C++ counterparts.

This[^] would be a good place to start.


我认为您可能需要考虑
I think you might need to consider the example of C# Com interop [^]

Hope it helps :)


这篇关于创建外部功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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