I have made a DLL with VC++ 2008 and when i use it in console application VC++ 6.0, there is an exception:
(msvcr90.dll): 0xc0000005: Access Violation
Access Violation
in this case can mean so many things, and the msvcr90.dll
reference can be very much misleading. If you pass invalid data to any of the MSVC standard library functions, the access violation will occur within msvcr90.dll
and not in your code (when viewing the stack trace or looking at the exception info.
That said, there should not, in theory, be a problem using a VC9 DLL in VC++ 6, as the ABI has not changed and the PE format is the same. You might have problems if msvcrt9.dll
is unsupported on your platform (for instance if you're running MSVC6 on Windows NT), but otherwise it means you need to review your code.
What I mean is: attach a debugger and look at what's happening beneath the scene!
One more note: when using different versions of the MSVC libraries dynamically, you MUST NOT allocate data in one library and free it in another as they are not guaranteed to be using the same heap and you can get memory corruption (and Access Violation
errors) rather easily like this. This also means that if you're writing C++, you must not create an object and then pass it by return value to the calling app as that's what will happen beneath the scenes.
If you want to build a DLL with Visual C++ version X and use it in Visual C++ version Y, you have some options:
- Build a DLL which exposes a pure C interface. You can use C++ inside the DLL, but the public interface must be pure C (so, for example, you can't throw exceptions crossing DLL boundaries).
- Build a COM DLL (possibly with the help of tools like ATL).
- Build a DLL using COM-like techniques, i.e. expose only abstract interfaces and factory functions from your DLL (this technique is explained in this article on CodeProject "HowTo: Export C++ classes from a DLL", in particular in the paragraph "C++ Mature Approach: Using an Abstract Interface").
It is also important to point out that the code which allocates memory and the code which frees memory must use the same allocator.
来源:https://stackoverflow.com/questions/9979859/can-i-create-dll-with-vc-2008-and-use-it-in-vc-6