dll 在 VS2010 项目中工作正常,但在 VS6 应用程序中出现访问冲突 [英] dll works fine in a VS2010 project but gives access violations in a VS6 Application
问题描述
过去几周我一直在为 USB 设备创建一个 dll,该设备带有自己的 dll,我用来在 VS2010 中创建自己的 dll,然后我创建了一个测试应用程序,该应用程序在 2010 年使用该 dll让它工作.它运行良好,但是我现在需要在 VS6 项目中使用它,当我使用它时,我遇到了访问冲突,我在 VS6 中重新创建了 dll 以查看是否有帮助,它允许我尽快进入代码它在我的 dll 中调用了 3rd 方 dll 的一行,它导致访问冲突,我刚刚尝试创建一个工厂函数来为我的 dll 创建一个抽象接口,但我再次遇到访问冲突.我是 dll 的新手,我完全没有想法,帮助或洞察力将非常有用...
I have been creating a dll for a usb device over the past few weeks, the device came with its own dll which i used to create my own dll in VS2010, I then created a test application which uses said dll in 2010 to get it working. It works well, however I now need to use it in a VS6 project, when i use it I get access violations, I recreated the dll in VS6 to see if that would help, it allowed me to step into the code, as soon as it gets to a line in my dll that calls the 3rd party dll, it causes an access violation, I have just tried creating a factory function to create a abstract interface to my dll but I again get access violations. I am new to dlls and am completely out of ideas, and help or insight would be greatly appritiated...
推荐答案
获得使用更高版本的 Visual Studio 创建的 DLL 以与 Visual Studio 6 一起使用的方法是按照通用方式对 DLL 进行编码传递和返回到 DLL 导出函数的参数.
The way you can get a DLL created with a later version of Visual Studio to work with Visual Studio 6 is to code your DLL in a generic way in terms of parameters passed and returned to the DLL's exported functions.
例如,Windows API 描述了某些变量类型.这些类型包括DWORD
、LONG
、BOOL
、DWORD_PTR
等,包括各种字符串指针类型,如LPCSTR
.此列表中还包括指向这些不同类型的指针,例如 LPLONG
、LPBYTE
、LPVOID
等.
For example, the Windows API describes certain variable types. These types include DWORD
, LONG
, BOOL
, DWORD_PTR
, etc. Included are the various string pointer types such as LPCSTR
. Also included in this list are pointers to these various types such as LPLONG
, LPBYTE
, LPVOID
etc.
如果您的 DLL 的导出函数传递或返回的类型不是上述类型之一,那么您就会陷入困境——该 DLL 只能在使用相同版本的 Visual Studio 构建的应用程序中安全使用DLL 是用它构建的.
If your DLL's exported functions passes or returns a type that isn't one of the above, then you're stuck -- the DLL can only be used safely in an application that was built with the same version of Visual Studio that the DLL was built with.
例如,如果您要传递 C++ 对象(标准库对象,甚至您自己的对象),如果您希望该 DLL 在多个版本的 Visual Studio 中工作,这是一个很大的禁忌.
For example, if you're passing C++ objects (standard library objects, or even your own objects), that is a big no-no if you want that DLL to work across several versions of Visual Studio.
这篇关于dll 在 VS2010 项目中工作正常,但在 VS6 应用程序中出现访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!