Click here to Skip to main content
15,904,935 members
Home / Discussions / C#
   

C#

 
GeneralRe: Setting an object public property, protected by a security check Pin
Mycroft Holmes15-Aug-09 0:39
professionalMycroft Holmes15-Aug-09 0:39 
AnswerRe: Setting an object public property, protected by a security check Pin
Adam Maras14-Aug-09 23:47
Adam Maras14-Aug-09 23:47 
GeneralRe: Setting an object public property, protected by a security check Pin
pierpaolo paparo14-Aug-09 23:54
pierpaolo paparo14-Aug-09 23:54 
GeneralRe: Setting an object public property, protected by a security check Pin
Adam Maras14-Aug-09 23:59
Adam Maras14-Aug-09 23:59 
AnswerRe: Setting an object public property, protected by a security check Pin
PIEBALDconsult15-Aug-09 4:24
mvePIEBALDconsult15-Aug-09 4:24 
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 
I'm using some midi API functions that take a MIDIHDR structure.
[StructLayout(LayoutKind.Sequential)]
public struct MIDIHDR
{
    public IntPtr lpData;
    public int dwBufferLength;
    public int dwBytesRecorded;
    public IntPtr dwUser;
    public int dwFlags;
    public IntPtr lpNext;
    public IntPtr reserved;
    public int dwOffset;
    public IntPtr dwReserved;
}
lpData is a pointer to the data. This data is an array of MIDIEVENT structures
[StructLayout(LayoutKind.Sequential)]
public struct MIDIEVENT
{
    public uint dwDeltaTime;
    public uint dwStreamID;
    public uint dwEvent;
}
If I only have one element in the array I can use
int eventSize = Marshal.SizeOf(ev) * events.Length;
IntPtr eventPointer = Marshal.AllocHGlobal(eventSize);
for (int i = 0; i < events.Length; i++)
    Marshal.StructureToPtr(events[i], (IntPtr)((int)eventPointer + (eventSize * i)), false);
but I get Arithmetic operation resulted in an overflow when the second event is reached when playing the events (midiStreamRestart(handle)) if there is more than one element.

So, what's the best way to marshal an array of structures, and why doesn't the above work?

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Friday, August 14, 2009 6:20 PM

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 
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 

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.