QUOTE(zakary @ 21 May, 2008 - 04:39 AM)

can you post your unmanaged code that raps your dll. That is the code that matters your c and c++ methods you just need to know the parameters and return type.
The parameters and return type have no role here. What I did was to create a test project to test this problem and have posted the code in the previous post. Anyway, I could illustrate the problem a bit more here I guess.
CODE
//Wrapper class for the Pinvoke
class WrapperClass
{
[DllImport("unmanaged.dll")
public static extern int PopulateListView(IntPtr hwndDlg);
}
Now I tried something really simple. I created an unmanaged project and just wrote a simple function to update the list view.
CODE
__declspec(dllexport) void PopulateListView(HWND hTree)
{
LVITEM LvItem;
//attempt to insert 10 listview items
for(int i=0;i<10;i++)
{
LvItem.iIndex = i;
LvItem.pszText = "Hello"; //some string value
LvItem.mask = LVIF_TEXT;
SendMessage (hTree,LVM_INSERTITEM,0,(LPARAM)&LvItem);
//now insert some attributes for each item
for(int j = 0;j<4;j++)
{
LvItem.iSubItem = j;
LvItem.mask = LVIF_TEXT;
SendMessage (hTree,LVM_SETITEM,0,(LPARAM)&LvItem);
}
}
}
I am calling this ofcourse as mentioned earlier, ie passing the handle of the listview control.
This sets my listview properly and I can see all the items in the UI. But as soon as I click on it, or do a slight drag, it throws an ArgumentOutOfRangeException.
Upon debugging, I found that after the unmanaged code has finished executing, the count of items in the listview still remains 0!

How is this possible? I can see the bloody items in the UI, so why aren't they showing up in the count!
This has driven me nuts and now I am contemplating passing delegates to just get the values from the unmanaged code and update the list view myself in the managed code. But this would involve a major rewrite of the functions.
I suppose that the underlying architecture of all the controls should be the same, and any message sent to an unmanaged or managed code should do just fine. However, I may be wrong, and it certainly looks like the case
Help!!