Container & Dll
-
I've tried to make a Win32 Dll and pass around std::string's (they get filled in the dll and passed back to the calling process) The next step would be to pass a map to the dll, it gets filled there.. and the map is passed back to the caller. It looks like it doesn't work.. the data is passed around nicely.. but when the caller's var's are about to get deleted, it says that the memory was not allocated by this process (which is obvious) Is there any workaround ?
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous."
U.S. Secretary of State Colin Powell at George Bush's ranch in Texas -
I've tried to make a Win32 Dll and pass around std::string's (they get filled in the dll and passed back to the calling process) The next step would be to pass a map to the dll, it gets filled there.. and the map is passed back to the caller. It looks like it doesn't work.. the data is passed around nicely.. but when the caller's var's are about to get deleted, it says that the memory was not allocated by this process (which is obvious) Is there any workaround ?
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous."
U.S. Secretary of State Colin Powell at George Bush's ranch in TexasDon't know from the description if it is exacly your problem, but normally you have to free the memory in the same module you allocated it - therefore if you make '
malloc/new
' in a dll you have to call the 'free/delete
' in the same dll as well - this is because the exe and dll have different heaps - therefore if you allocate the memory at say0xabcdabcd
in dll and try to free it in exe module, he cannot find it. Solution is to: - either allocate it in exe and ask dll to fill it, then free it in exe (or vice versa for dll) - make some reference counting that will cause that delete is called in a correct module (like com does it when last reference is released) if you need more details, and if this describes the problem you have, don't worry to ask ;-) -
Don't know from the description if it is exacly your problem, but normally you have to free the memory in the same module you allocated it - therefore if you make '
malloc/new
' in a dll you have to call the 'free/delete
' in the same dll as well - this is because the exe and dll have different heaps - therefore if you allocate the memory at say0xabcdabcd
in dll and try to free it in exe module, he cannot find it. Solution is to: - either allocate it in exe and ask dll to fill it, then free it in exe (or vice versa for dll) - make some reference counting that will cause that delete is called in a correct module (like com does it when last reference is released) if you need more details, and if this describes the problem you have, don't worry to ask ;-)Sorry for my late answer.. but i couldn't access CodeProject yesterday. (404) Well.. the answer you've provided is exactly what i thought. The problem is.. i use the standard STL - Containers, and i just wanted to make sure, that i can't pass them around (exe -> dll -> exe) Thanks for your help, Bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous."
U.S. Secretary of State Colin Powell at George Bush's ranch in Texas