本文介绍了什么是安全的C + +插件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中的插件系统很难,因为ABI没有正确定义,每个编译器(或其版本)都遵循自己的规则。但是,Windows上的COM显示可以创建一个最小的插件系统,允许具有不同编译器的程序员使用简单的界面为主机应用程序创建插件。



让我们实用,离开C ++标准,这在这方面不是很有帮助,除了一分钟。如果我想为Windows和Mac(可选的Linux)编写一个支持C ++插件的应用程序,并且如果我想给插件作者一个相当大的编译器选择(比如说少于2年的Visual C ++版本,GCC或Intel的C ++编译器),我可以指望C ++的什么特性?



当然,我假设插件将被写入一个特定的平台。 / p>

在我的头顶,这里有一些C ++的功能,我可以想到,我认为是答案:




  • vtable布局,通过抽象类使用对象? (是)

  • 内置类型,指针? (yes)

  • 结构,工会? (是)

  • 例外? (no)

  • externC的功能? (是)

  • stdcall非外部C函数具有内置的参数类型? (是)

  • 非stdcall非外部C函数与用户定义的参数类型? (no)



我会感谢您在该区域拥有的任何经验。



Carl

解决方案

Dr Dobb's Journal有一篇文章,这是相当不错的阅读主题。这是一系列文章的开始,涵盖了C / C ++跨平台插件框架的架构,开发和部署。


Plug-in systems in C++ are hard because the ABI is not properly defined, and each compiler (or version thereof) follows its own rules. However, COM on Windows shows that it's possible to create a minimal plug-in system that allows programmers with different compilers to create plug-ins for a host application using a simple interface.

Let's be practical, and leave the C++ standard, which is not very helpful in this respect, aside for a minute. If I want to write an app for Windows and Mac (and optionally Linux) that supports C++ plug-ins, and if I want to give plug-in authors a reasonably large choice of compilers (say less than 2 year old versions of Visual C++, GCC or Intel's C++ compiler), what features of C++ could I count on?

Of course, I assume that plug-ins would be written for a specific platform.

Off the top of my head, here are some C++ features I can think of, with what I think is the answer:

  • vtable layout, to use objects through abstract classes? (yes)
  • built-in types, pointers? (yes)
  • structs, unions? (yes)
  • exceptions? (no)
  • extern "C" functions? (yes)
  • stdcall non-extern "C" functions with built-in parameter types? (yes)
  • non-stdcall non-extern "C" functions with user-defined parameter types? (no)

I would appreciate any experience you have in that area that you could share. If you know of any moderately successful app that has a C++ plug-in system, that's cool too.

Carl

解决方案

Dr Dobb's Journal has an article Building Your Own Plugin Framework: Part 1 which is pretty good reading on the subject. It is the start of a series of articles which covers the architecture, development, and deployment of a C/C++ cross-platform plugin framework.

这篇关于什么是安全的C + +插件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:20