Re: Throwing from DLL causes heap corruption

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Matt Osborn" <a@xxx> wrote in message
news:%23VTlex3VIHA.5508@xxxxxxxxxxxxxxxxxxxxxxx
C++ exceptions should not be thrown across module boundaries. You should
instead catch the exception at the entry point to the DLL (not
application entry point, but each exported DLL function) and indicate the
error in a portable way. Your options are:

(1) error/status code
(2) COM exception (which really is a status code)
(3) structured exception (not recommended for user-mode applications)

If this is true, then it is virtually impossible to intantiate an instance
of a class across a DLL boundary. How does the constructor report an
error without resorting to two stage construction techniques?

Using two return values (one must actually be an out parameter). One
indicates success or failure of instantiation, the other returns the pointer
to the new object.

See for example CoCreateInstance.


.



Relevant Pages