对于 C++ 插件系统,什么是安全的?

What#39;s safe for a C++ plug-in system?(对于 C++ 插件系统,什么是安全的?)

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

问题描述

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

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.

让我们切合实际,暂时搁置在这方面没有多大帮助的 C++ 标准.如果我想为 Windows 和 Mac(以及可选的 Linux)编写一个支持 C++ 插件的应用程序,并且如果我想为插件作者提供相当多的编译器选择(比如不到 2 年的 Visual C++ 版本)、GCC 或 Intel 的 C++ 编译器),我可以依靠 C++ 的哪些特性?

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.

以下是我能想到的一些 C++ 特性,我认为这就是答案:

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

  • vtable 布局,通过抽象类来使用对象?(是)
  • 内置类型、指针?(是)
  • 结构体、联合体?(是)
  • 例外?(不)
  • 外部C"函数?(是)
  • stdcall 具有内置参数类型的非外部C"函数?(是)
  • 具有用户定义参数类型的非标准调用非外部C"函数?(不)

如果您在该领域有任何经验可以分享,我将不胜感激.如果您知道任何具有 C++ 插件系统的成功应用程序,那也很酷.

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.

卡尔

推荐答案

Dr Dobb's Journal有一篇文章构建你自己的插件框架:第 1 部分,这是一个很好的阅读主题.这是一系列文章的开始,涵盖了 C/C++ 跨平台插件框架的架构、开发和部署.

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++ 插件系统,什么是安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:对于 C++ 插件系统,什么是安全的?

基础教程推荐