listview, sendmessage and System.NotSupportedException

  • Thread starter Pete Vickers [eMVP]
  • Start date
P

Pete Vickers [eMVP]

Hi,
i found some code in the groups to give the functionality of finditem on a
listview in full vb.net and attempted to port it to CF.
Unfortunately, it falls over with System.NotSupportedException when I call
the sendmessage.
Anyone see anything glaringly obvious in the code?

Thanks

Pete


Called as

iRet = Find_ListItem(lvResults, "fred")

Fails at sendmessage

Declare Function SendMessageFindItem Lib "Coredll" Alias "SendMessageW"
(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer,
ByRef lParam As LVFINDINFO) As Integer
Public Structure POINTAPI
Public x As Integer
Public y As Integer
End Structure

Public Structure LVFINDINFO
Public flags As Integer
Public psz As String
Public lParam As Integer
Public pt As POINTAPI
Public vkDirection As Integer
End Structure



Public Shared Function Find_Listitem(ByVal lv As ListView, ByVal sFind As
String) As Integer
Dim fi As LVFINDINFO
Dim result As Integer
fi.flags = 2 ' LVFI_STRING
fi.psz = sFind
fi.lParam = 0
fi.pt.X = 0
fi.pt.Y = 0
fi.vkDirection = 0
Dim lvHwnd As IntPtr
lv.Capture = True
lvHwnd = GetCapture()
lv.Capture = False
result = SendMessageFindItem(lvHwnd.ToInt32, LVM_FINDITEM, -1, fi)


End Function
 
P

Peter Foot [MVP]

The LVFINDINFO structure has an embedded string - the CF marshaller won't be
able to cope with this - although this works fine on the full framework. You
can get around this by allocating some native memory using a LocalAlloc()
P/Invoke to hold the string data and placing the IntPtr address to this
memory in the structure. Once you've finished with the structure call
LocalFree to free the allocated memory.

Peter
 
G

Geoff Schwab [MSFT]

Since I have it in front of me, here is the P/Invoke code in C#:

[DllImport("coredll.dll")]
extern public static IntPtr GetCapture();

public const uint LMEM_FIXED = 0;
public const uint LMEM_MOVEABLE = 2;
public const uint LMEM_ZEROINIT = 0x0040;

[DllImport("coredll.dll")]
extern public static IntPtr LocalAlloc(uint uFlags, uint uBytes);

[DllImport("coredll.dll")]
extern public static IntPtr LocalFree(IntPtr hMem);

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Pete Vickers [eMVP]

Hi,
thanks for the info. Now runs, but always returns 0 when executed. Ah well -
back to the drawing board

Pete
 
N

.Net Compact Framework

Hi Peter,

I am current working on a project in C# and have come across the exact same
problem. Have you been able to get this working?
 
P

Peter Foot [MVP]

I think the issue is that the structure (LVFINDINFO) contains a string which
is not supported by the .NETCF marshaller. If you replace this with an
IntPtr and allocate some unmanaged memory into which to copy the string
contents this should work (remember to free up this memory after use). I've
posted a working C# version here:-
http://www.opennetcf.org/public/ListViewHelper.zip

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org


.Net Compact Framework said:
Hi Peter,

I am current working on a project in C# and have come across the exact same
problem. Have you been able to get this working?


Pete Vickers said:
Hi,
thanks for the info. Now runs, but always returns 0 when executed. Ah well -
back to the drawing board

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
i found some code in the groups to give the functionality of finditem
on
 
N

.Net Compact Framework

thanks for the quick response however the link does not seem to be
accessbile. Do you think you can forward this to me?

Peter Foot said:
I think the issue is that the structure (LVFINDINFO) contains a string which
is not supported by the .NETCF marshaller. If you replace this with an
IntPtr and allocate some unmanaged memory into which to copy the string
contents this should work (remember to free up this memory after use). I've
posted a working C# version here:-
http://www.opennetcf.org/public/ListViewHelper.zip

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org


Hi Peter,

I am current working on a project in C# and have come across the exact same
problem. Have you been able to get this working?


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
thanks for the info. Now runs, but always returns 0 when executed. Ah well -
back to the drawing board

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
i found some code in the groups to give the functionality of
finditem
on I
call sFind
As LVM_FINDITEM, -1,
fi)
 
N

.Net Compact Framework

Never mind my link was down. Sorry about that!

Peter Foot said:
I think the issue is that the structure (LVFINDINFO) contains a string which
is not supported by the .NETCF marshaller. If you replace this with an
IntPtr and allocate some unmanaged memory into which to copy the string
contents this should work (remember to free up this memory after use). I've
posted a working C# version here:-
http://www.opennetcf.org/public/ListViewHelper.zip

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org


Hi Peter,

I am current working on a project in C# and have come across the exact same
problem. Have you been able to get this working?


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
thanks for the info. Now runs, but always returns 0 when executed. Ah well -
back to the drawing board

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
i found some code in the groups to give the functionality of
finditem
on I
call sFind
As LVM_FINDITEM, -1,
fi)
 
N

.Net Compact Framework

Thanks Peter, I found my mistake after reviewing your sample. I have
another question, If my list contains multiple columns is there a way to
indicate which column to search? I tried changing the POINTER.X but that
didn't work.


Peter Foot said:
I think the issue is that the structure (LVFINDINFO) contains a string which
is not supported by the .NETCF marshaller. If you replace this with an
IntPtr and allocate some unmanaged memory into which to copy the string
contents this should work (remember to free up this memory after use). I've
posted a working C# version here:-
http://www.opennetcf.org/public/ListViewHelper.zip

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org


Hi Peter,

I am current working on a project in C# and have come across the exact same
problem. Have you been able to get this working?


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
thanks for the info. Now runs, but always returns 0 when executed. Ah well -
back to the drawing board

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
i found some code in the groups to give the functionality of
finditem
on I
call sFind
As LVM_FINDITEM, -1,
fi)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top