Click here to Skip to main content
15,893,487 members
Home / Discussions / C#
   

C#

 
Questionabout the hashtable remove Pin
elvis_pan14-Aug-09 16:12
elvis_pan14-Aug-09 16:12 
AnswerRe: about the hashtable remove Pin
Luc Pattyn14-Aug-09 16:53
sitebuilderLuc Pattyn14-Aug-09 16:53 
QuestionPInvoke, varaible length arrays [Solved] Pin
DaveyM6914-Aug-09 11:29
professionalDaveyM6914-Aug-09 11:29 
AnswerRe: PInvoke, varaible length arrays [modified] Pin
Pete O'Hanlon14-Aug-09 11:44
mvePete O'Hanlon14-Aug-09 11:44 
GeneralRe: PInvoke, varaible length arrays Pin
Luc Pattyn14-Aug-09 11:53
sitebuilderLuc Pattyn14-Aug-09 11:53 
GeneralRe: PInvoke, varaible length arrays Pin
Pete O'Hanlon14-Aug-09 11:57
mvePete O'Hanlon14-Aug-09 11:57 
GeneralRe: PInvoke, varaible length arrays Pin
DaveyM6914-Aug-09 12:15
professionalDaveyM6914-Aug-09 12:15 
AnswerRe: PInvoke, varaible length arrays Pin
Luc Pattyn14-Aug-09 11:46
sitebuilderLuc Pattyn14-Aug-09 11:46 
Hi Dave,

I have avoided such complexities till now, except for once, a rather simple variable array length.

Here are the results of the Antwerp jury:
In
[1]  int eventSize = Marshal.SizeOf(ev) * events.Length;
[2]  IntPtr eventPointer = Marshal.AllocHGlobal(eventSize);
[3]  for (int i = 0; i < events.Length; i++)
[4]      Marshal.StructureToPtr(events[i], (IntPtr)((int)eventPointer + (eventSize * i)), false);


There is something fishy about eventSize;
[1] is an attempt to compute the overall size; it may be correct, I am not sure, as Sizeof(ev) is the size of one struct and could be rounded up to a multiple of 16 or so, whereas an array would not contain padding bytes between elements.
And [4] treats eventSize as if it were the size of a single element, which it isn't. So that is probably the direct cause of your overflow.
Seems like you want to move the multiplication from [1] to [2].

FWIW: IntPtr will adapt to Win32/Win64 as you probably know; don't let it fool you.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

GeneralRe: PInvoke, varaible length arrays Pin
Pete O'Hanlon14-Aug-09 11:54
mvePete O'Hanlon14-Aug-09 11:54 
GeneralRe: PInvoke, varaible length arrays Pin
Luc Pattyn14-Aug-09 11:56
sitebuilderLuc Pattyn14-Aug-09 11:56 
GeneralRe: PInvoke, varaible length arrays Pin
Pete O'Hanlon14-Aug-09 11:59
mvePete O'Hanlon14-Aug-09 11:59 
GeneralRe: PInvoke, varaible length arrays Pin
Luc Pattyn14-Aug-09 12:03
sitebuilderLuc Pattyn14-Aug-09 12:03 
GeneralRe: PInvoke, varaible length arrays [Solved] Pin
DaveyM6914-Aug-09 12:09
professionalDaveyM6914-Aug-09 12:09 
GeneralRe: PInvoke, varaible length arrays [Solved] Pin
Luc Pattyn14-Aug-09 12:17
sitebuilderLuc Pattyn14-Aug-09 12:17 
GeneralRe: PInvoke, varaible length arrays [Solved] Pin
DaveyM6914-Aug-09 12:54
professionalDaveyM6914-Aug-09 12:54 
GeneralRe: PInvoke, varaible length arrays [Solved] Pin
Luc Pattyn14-Aug-09 13:01
sitebuilderLuc Pattyn14-Aug-09 13:01 
GeneralRe: PInvoke, varaible length arrays [Solved] Pin
DaveyM6914-Aug-09 13:08
professionalDaveyM6914-Aug-09 13:08 
GeneralRe: PInvoke, varaible length arrays [Solved] Pin
DaveyM6921-Apr-10 10:38
professionalDaveyM6921-Apr-10 10:38 
AnswerRe: PInvoke, varaible length arrays Pin
Hristo-Bojilov14-Aug-09 12:15
Hristo-Bojilov14-Aug-09 12:15 
GeneralRe: PInvoke, varaible length arrays Pin
DaveyM6914-Aug-09 12:20
professionalDaveyM6914-Aug-09 12:20 
GeneralRe: PInvoke, varaible length arrays [modified] Pin
Hristo-Bojilov14-Aug-09 12:33
Hristo-Bojilov14-Aug-09 12:33 
QuestionUpdate db table Linq Pin
spankyleo12314-Aug-09 10:05
spankyleo12314-Aug-09 10:05 
AnswerCross posted from the LINQ forum Pin
Pete O'Hanlon14-Aug-09 10:33
mvePete O'Hanlon14-Aug-09 10:33 
GeneralRe: Cross posted from the LINQ forum Pin
spankyleo12314-Aug-09 10:39
spankyleo12314-Aug-09 10:39 
GeneralRe: Cross posted from the LINQ forum Pin
Pete O'Hanlon14-Aug-09 10:54
mvePete O'Hanlon14-Aug-09 10:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.