I tried to create a win32 dll using c++. It has a map declared globally. But when I try to access the map using the dll its giving a run time error that: WindowsError: exception: access violation reading 0x00000008. How to solve it?
Declaration: static map<int,urllib> url_container;
The urllib is a class.
Error occurance: url_container[ucid] = urllib();
The error occurs at the above point.
Does this code
get called in a static initialiser for an other global object? If so there is no guarantee that
url_containerhas been consutructed before the other global object.Use an accessor function to control when the object is created, or use a singleton library like boost singleton
Accessor example
As an aside I would suggest you try to avoid global objects. As you could spend the rest of your life debugging issues like this. Eventually the construction of one global object will depend on another etc. and the order of construction is not defined so it might work on one platform/compiler and fail on another.