简体   繁体   English

使用在 VS 2019 环境中开发的 DLL 在尝试启动 VS 2008 环境中内置的 exe 时触发崩溃

[英]Using a DLL developed on VS 2019 environment triggering crash when tried to launch an exe built in VS 2008 Environment

I have a DLL that is developed in VS 2019 environment.我有一个在 VS 2019 环境中开发的 DLL。

It has following Interface.它具有以下接口。

bool Initialize();
{
     // Do nothing
}

Interface declaration in DLL DLL中的接口声明

extern "C" CDACVS19LIBRARY_API bool Initialize();

I uses the above Interface in one of the console exe created in VS2008 Environment as follows.我在 VS2008 环境中创建的控制台 exe 之一中使用上述接口,如下所示。

Initialize();初始化();

When I invoke this interface it is throwing below error当我调用此接口时,它会抛出错误

Run-time Check Failure #2 - Stack around the variable 'oss_' was corrupted.

What is wrong in the above code/approach?上面的代码/方法有什么问题?

There is something wrong about using a dll built in VS2019 environment in an exe developed in VS 2008 environment as we are using something built in later version in older version.在 VS 2008 环境中开发的 exe 中使用 VS2019 环境中内置的 dll 存在问题,因为我们在旧版本中使用的是后期版本中内置的东西。

Is it not possible to do so?难道不能这样做吗? If possible, where I am not right in following the above approach?如果可能的话,我在哪里不正确地遵循上述方法?

If I use the same dll in a console exe built in 2019 environment, everything works just fine.

EDIT : Edited to make Interface declaration and definition proper.编辑:编辑以使接口声明和定义正确。

First of all your declarations and defintions must match exactly.首先,您的声明和定义必须完全匹配。

Secondly,if you want your DLL to be used by any program (no matter which compiler\language used) you must not use anything that could change by compilerversions in the DLL-interface.其次,如果您希望您的 DLL 被任何程序使用(无论使用哪种编译器\语言),您不得使用任何可能被 DLL 接口中的编译器版本更改的内容。 This means restrict your DLL-interface to C-compatible functionalities,don't expose any STL-stuff or templates and do not rely on default calling-conventions for functions (decorate them as extern "C" or _cdecl).这意味着将您的 DLL 接口限制为与 C 兼容的功能,不要公开任何 STL 材料或模板,并且不要依赖函数的默认调用约定(将它们装饰为 extern "C" 或 _cdecl)。 Write your interfaces as if your writing for C.编写您的界面,就像您为 C 编写一样。 Inside your DLL you do whatever you want.在您的 DLL 内,您可以随心所欲。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM