Another somewhat related question is this; I'm having trouble filling a DBPro array from a plugin.
From reading through the DarkSDK source on some array functions it seems this approach should be appropriate, yet it seems the array only contains uninitialized heap memory once control gets back to DBPro from the dll:
// This has a string table command string of "H*D"
DBFUNC DWORD dbfEnumerateChildInstances(DWORD dwArrayPtr, cInstance *ptr) {
// This works just fine and gives me a list of (valid) pointers when debugging the dll in action from within DBPro
std::vector<cInstance*> list;
ptr->EnumerateChildren(list);
// Empty the DBPro array
dbEmptyArray(dwArrayPtr); // This seems to work too; if everything else is removed from this function it clears the array
if(list.empty())
return dwArrayPtr;
// And resize it so that it can contain the child list
DWORD dwAllocation = dbExpandArray(dwArrayPtr, list.size());
// Ensure that the internal array index doesn't point at -1; the array isn't going to be empty if we get here
*((DWORD*)dwAllocation - 1) = 0;
// Add the child instances to the DBPro array as a set of DWORD's
for(size_t l = 0; l < list.size(); l++)
*((DWORD*)dwAllocation + l) = (DWORD)list[l];
// Overwrites current array ptr in DBPro
return dwAllocation;
}
Any idea on what might cause that? Is there some further things that have to be done in order to write to an array?
The array in question is declared as
dim arr(0)
as dword from DBPro. After calling the above function,
array count reports the appropriate number of elements but trying to read or write to the array causes access violations.
Edit: got it figured out, it seems each array item is actually another pointer to where the actual element data is stored.
"Why do programmers get Halloween and Christmas mixed up?" Because Oct(31) = Dec(25)