在 C++ 中编写控件的最佳方法是什么?以便它可以被 C++ 使用和 C# 程序?

发布于 2025-01-02 13:30:30 字数 398 浏览 2 评论 0原文

我有一个用 C# 编写的自定义控件,我想将其移植到 C++,因为它太慢,而且我想在 C++ 程序和 C# 程序中使用它。

我研究过 MFC Active X、ATL Active X 和 .NET C++。它们看起来都过于复杂。我真的很想避免使用 .NET C++,因为在 C++ 程序中涉及 .NET 似乎毫无意义。

此外,似乎没有任何关于编写 10 年前的 Active X 控件的优秀教程。

你们知道有哪些针对 Visual Studio 2008 的不错的 ActiveX 教程吗?

有没有其他方法可以让我无需编写 COM 组件即可实现我的目标。我可以用 C++ 编写一个普通控件并将其粘贴到 DLL 中并使其可供 C++ 和 C# 程序使用吗?我不关心与 GUI 表单设计器的兼容性。

谢谢!

I have a custom control written in C# that I would like to port to C++ because it is too slow, and also because I would like to use it in a C++ program as well as C# programs.

I've looked at MFC Active X, ATL Active X, and .NET C++. They all seem needlessly complicated. I'd really like to avoid .NET C++ because involving .NET in a C++ program just seems pointless.

Also there don't seem to be any good tutorials on writing active X controls that aren't a decade old.

Do you guys know of any decent ActiveX tutorials that target Visual Studio 2008?

Is there any other way that I can accomplish my goals without having to write a COM component. Can I just write a normal control in C++ and stick it in a DLL and have it be usable by both C++ and C# programs? I don't care about compatibility with GUI form designers.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2025-01-09 13:30:30

我原来的答案如下。我将把它留给有类似情况的人。

如果除了复杂的数学之外,C# 比 C++ 慢,那么你就做错了。它的速度即使不是更快,也应该接近相等。

C++ 本质上意味着制作 GUI 将涉及大量复杂性、重新发明轮子和旧文档。这是无法避免的。

“在 C++ 程序中涉及 .NET 似乎毫无意义”这一事实对我来说表明您对所使用的技术知之甚少。

我的答案:坚持使用 C#,否则你会不知所措。专注于优化现有资源,而不是重新发明轮子。

编辑:正如 Jeff Mercado 所说,如果您确实决定采用本地路线,我祝您的互操作事业好运。

根据您的评论,我仍然担心您不了解 .NET C++(最近被 C++/CLI 取代)所扮演的角色。我认为这可能是您的完美解决方案。例如,它允许您用 C++ 编写一个 ActiveX 控件(这是我目前推荐的),然后立即为其编写一个 .NET 包装器,而无需离开 C++,而是使用相当大的 C++ 扩展。

还有一个补充:如果可能的话,使用 Visual Studio 2010。 C++/CLI 比其前辈有了巨大的进步。至于 ActiveX,如果指南是旧的,请不要担心。过去十年没有太大变化。

My original answer was as follows. I will leave it here for people in similar situations.

If C# is slower than C++ for anything other than complex mathematics, you are doing something wrong. It should be near equal in speed, if not faster.

C++ inherently means making a GUI is going to involve lots of complexity, reinventing of the wheel, and old documentation. There is no avoiding it.

The fact that "involving .NET in a C++ program seems pointless" indicates to me that you know very little about the technologies with which you are working.

My answer: stick with C#, or you will be in over your head. Focus on optimizing what you have, not reinventing the wheel.

Edit: As Jeff Mercado said, if you do decide to take a native route, I wish you luck with your interop ventures.

Based on your comment, I am still concerned that you don't understand the role that .NET C++ (recently replaced by C++/CLI) plays. I think that might just be the perfect solution for you. It allows you to, say, write an ActiveX control in C++ (which is what I would recommend at this point), and then immediately write a .NET wrapper for it without leaving C++, but instead using a rather large C++ extension.

Yet another addition: Use Visual Studio 2010 if at all possible. C++/CLI is a huge improvement over its predecessors. As for ActiveX, don't worry if the guides are old. It hasn't changed much in the past decade.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文