Using errno in DLLs

Using errno in DLLs

C++ inherited from C the global variable errno which indicates the success status of a previous operations. An errno value of 0 indicates that the previous operation was successful whereas anon-zero value indicates an error of some sort. To get the actual error message, call the perror() function (declared in stdlib.h). As with all global variables, errno is problematic in multithreaded environments because every thread may change its value. Multithreaded environments often solve this problem by making errno a thread-safe function rather than a variable. When using DLL’s, though, errno is even more problematic: the main process and the DLL’s it uses have independent instances of errno. Therefore, you can’t use errno reliably in applications that use DLL’s. Although there are techniques to overcome this problem, my advice is to abandon errno and use exception handling or some other object-oriented technique of reporting and detecting runtime errors.

See also - an AI reverse image search platform

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist