Hello all,
 
I am a new Hunspell integrator. I am trying to integrate hunspell into a .NET 1.1 application. I have been sucessfull in
1. Building a dll build of libhunspell in visual studio
2. Exporting the spell and suggest functions into .NET
3. Marshalling the data types between the managed and unmanaged code.
 
I can get a list of suggested words and can export them into my application, but am having problems cleaning up the memory allocated by hunspell in my dll. When I call free on the suggested words and the continaing array, an exception is thrown from the _CtrIsValidHeapPointer function in dlgheap.c
 
I have looked into this and think it is to do with the heap that the memory is allocated onto in hunspell is different to the one I am trying to free it from in my .net managed code. I have tried building the hunspell dll in MultiThreaded and Multithreaded dll modes (my application is using the Multi Threaded option) but this makes no difference. Is there a way that I can free this memory in the hunspell code rather than my application? Or can anyone advise me on how to operate on the correct heap to free the memory?
 
I have code similar to this:
 
ArrayList * myClass::arlSuggest(String * sWord)
{
   // Convert marshalled string into unmanaged code
   IntPrt * pWord = Marshal::StringToHGlobalAnsi(sWord);
 
   // Call sugest on previously initilised hunspell instance
   const char * szWord = static_cast<char*>(pWord.ToPointer);
   char ** paWordList = NULL;
   int iNoOfSuggestions = m_pstHunspellInstance->suggest(&paWordList, szWord);
 
   // Fill arraylist with suggested words
   ArrayList * arlSuggestedWords = new ArrayList(iNoOfSuggestions);
   for (int i = 0; i < iNoOfSuggestions; i++)
   {
      char * szSuggestedWord = static_cast<char*>(paWordList[i]);
      arlSuggestedWords->Add(new String(szSuggestedWord));
    
      // The following line throws an exception, from _CtrIsValidHeapPointer(pUserData)
      free(szSuggestedWord);
   }
   // The following also throws an exception
   if (paWordList) free (paWordList);
 
   return arlSuggestedWords;
}

--
Laurie Mercer
_________________________
lsmercer@gmail.com