void __declspec(dllexport) MakeList(std::list<CMyClass>& list); //문제 1 사용 후 caller의 stack이 pop-up되는 경우나 caller가 list.clear()를 호출 할 때 access viloation이 발생한다. -_-; STL 자체를 DLL의 export symbol에 사용하는 것 자체가 많의 주의를 요하는 것 같다. 아무튼 원인은 (짧은 영어로 후다닥 읽어 보고 예전의 경험을 + 하면) STL의 대부분의 class들을 static member를 직/간접적으로 사용하고 있으며 이 것은 dll (또는 exe) 내부에서 instance들이 생성될 때 static memeber들을 가지게 되는 것을 의미하고, 그로 인해 static member들 간의 sync.가 맞지 않아서 access viloation이 발생한다는 것이다. 문제 1의 경우 caller (out of dll)와 caller (in dll)의 list instance 들의 static member (in STL)의 sync.가 맞지 않아서 문제가 생기는 것 같다. (debuging을 해보면 list를 caller가 clear할 때 발생한다. 아무튼 해결책은 -_-;; std::list<CMyClass>&를 parameter로 사용하지 않고 void* linked list (자체 제작한) 을 사용해서 해결하기는 했다. Ref. 1 나와 같이 괴로워하는 이들의 이야기들.. Ref. 2 STL의 대부분의 class는 static data member를 직,간접적으로 사용하기 때문에 dll 내부의 static data member와 dll 외부 caller의 static member가 sync.가 맞지 않아서 access violation이 발생할 수 있다. Wrapper function을 두어서 간접적으로 STL instance에 접근 http://support.microsoft.com/kb/q172396/ Ref3. 마지막 답변에 2003, 2005에서 STL containers를 export할 수 있는 macro set이 있다. Ref4. 다음 두 주제에 대해서 다루고 있다.
http://support.microsoft.com/kb/q168958/ How to export an instantiation of a Standard Template Library (STL) class and a class that contains a data member that is an STL object ref in this blog DLL내에서 STL을 사용했을 때 발생하는 warning에 대해서 http://alones.byus.net/tt/entry/tempSTL을-DLL에서-썼을-때의-문제-점 |
