Reputation: 8237
i have this code:
lvItem.pszText = (IntPtr)(lpRemoteBuffer + Marshal.SizeOf(typeof(LV_ITEM)));
it works fine on 4.0.
if i downgrade the project to 3.5 it gives me this error :
Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'
any idea how do i fix that to make it work on 3.5
and i dont know why it works in 4.0 ?
thanks in advance
Upvotes: 3
Views: 2449
Reputation: 11357
IntPtr didn't support pointer arithmetic prior to .NET 4.0. If you want to work that way with pointers, you have to use real pointers insteat of IntPtr.
Upvotes: 0
Reputation: 1500983
Yup - if you look at the documentation for the Addition property you'll see that operator was only introduced in .NET 4. You shouldn't need the cast, by the way.
On .NET 3.5 you could probably use:
lvItem.pszText = new IntPtr(lpRemoteBuffer.ToInt64() +
Marshal.SizeOf(typeof(LV_ITEM)));
Of course you then need to hope you're not on a 32-bit system with a pointer which goes over int.MaxValue
:)
Upvotes: 8