1

I've got a windows dll that throws std::system_errors with category std::system_category().

If they get caught inside the dll, no problem I can compare them with a std::error_condition'. But, if I catch in my exe that links to the dll, then comparisons always fail because the std::system_category() in that context does not == the one in the caught exception.

I'm struggling to understand if this should work and there's a bug, or if this shouldn't be supported?

Both the dll and exe link to the same dll version of the CRT.

Also, if the dll and exe linked to static versions of the CRT, I guess this wouldn't be expected to work?

I read this description of std::system_category, (emphasis mine):

Obtains a reference to the static error category object for errors reported by the operating system.

1 Answer 1

2

This is a bug in Visual C++ 2013. It is fixed in Visual C++ 2015.

3
  • Ok, thanks. I got the second part of my question wrong, maybe you also know the answer: "f the dll and exe linked to static versions of the CRT, I guess this wouldn't be expected to work?" Sep 18, 2015 at 16:01
  • @ScottLangham This won't work at all in Visual C++ 2013 regardless how you link things; the operator== will compare the addresses of error_category objects in two different modules and return false. In Visual C++ 2015, it will work if both modules link to the Visual C++ libraries DLLs. If you statically link the Visual C++ 2015 libraries into each module, then this will still happen to work, though it is highly inadvisable to do so, Sep 18, 2015 at 16:04
  • @JamesMcNellis How does that work? Usually statically linking a library into different DLLs duplicates all content of said static library. I want the same capability for my own variables. Dec 16, 2019 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.