I need to write a .NET Managed wrapper for C++ function defined as follows:
void getMap(CMapStringToString*& Map);
This function stores in the necessary information in the Map variable.
Now I wrapped the function as follows but I somehow do not get the correct output from the wrapped function:
void GetMap(System::Collections::Specialized::StringDictionary ^% nMap)
{
CMapStringToString orig_map, *map = &orig_map, *&mapRef = map;
m_pUnmanagedObject->getMap(mapRef);
for(POSITION pos = orig_map.GetStartPosition(); pos != NULL; )
{
CString key, pa, &paRef = pa;
orig_map.GetNextAssoc(pos, key, paRef);
nMap->Add(gcnew System::String((LPCTSTR)key), gcnew System::String((LPCTSTR)pa));
}
}
There is definitely something wrong with the wrapper because when I use the C++ code I get the correct output but when I use the wrapper code, the nMap is empty (i.e. in C# when I did nMap.Count, it returned 0 whereas for that same example in C++ I was getting 6)
Replace
and
with
and