On Jul 20, 2006, at 12:45 PM, Adam Ernst wrote:

How can I construct a char** array to pass to a declare? I've tried the following, but it doesn't seem to work (attrs is a string array, which I am attempting to convert into a memoryblock):

  dim attrP as MemoryBlock
attrP = new MemoryBlock((UBound(attrs)+2)*4) // Num elements, plus one for NULL termination, times pointer size
    for lc as Integer = 0 to UBound(attrs)
      dim m as new MemoryBlock(LenB(attrs(lc))+1)
      m.CString(0) = attrs(lc)
      attrP.Ptr(lc*4) = m
    next

It would help to know what you mean by "doesn't seem to work", but I'd guess that the problem is you aren't keeping any permanent references to the string memoryblocks. The loop creates a new memoryblock for each string, copies data into it, then forgets about it, at which point the memoryblock is deleted. This leaves a dangling pointer in your array buffer. The solution is to keep a list of the blocks you've allocated until the call to the external library returns.

Mars Saxman
REAL Software
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to