Hello, i've encountered a strange little thing. I pass a pointer by reference to a function in a DLL. The function creates a dynamic array from the pointer by using new. That works fine, the data in the array is filled like it should. But, when I try to delete the array from the main program, delete throws a runtime error. :/ any clues?
Function from my DLL:
Code in my main program:Code:void DDraw::Get_Enumeration_Result(Enum_Result *&result, int &resultCount) { int idx = 0, sz = (int)deviceEnum.size(); result = new Enum_Result[sz]; resultCount = sz; for(enumIterator = deviceEnum.begin(); enumIterator != deviceEnum.end(); ++enumIterator) { Enum_Result tmp = (Enum_Result)*enumIterator; result[idx].enumWidth = tmp.enumWidth; result[idx].enumHeight = tmp.enumHeight; result[idx].enumDepth = tmp.enumDepth; idx++; } }
Code:Enum_Result *res = NULL; int count; gfx->Get_Enumeration_Result(res, count); for(int i = 0; i < count; i++) { char txt[100]; sprintf(txt, "%dx%dx%d", res[i].enumWidth, res[i].enumHeight, res[i].enumDepth); MessageBox(hWnd, txt, "Enum", MB_OK); } delete[] res;




Reply With Quote