midi API MIDIHDR String MarshalAs...

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I am having problems using interop to call midiOutLongMsg.

in my MIDIHDR struct, i allocate MsgData as a string

I have been using a StringBuilder object to build MsgData
per byte. I am not getting the proper results, although
sometimes I do hear some notes being played, just not the
right ones...

What I think is happening is that when I do something like:

byte b=153;
Stringbuilder sb = new StringBuilder();
sb.Append(b);

i am appending the "string representation" of the byte.
ie "153" instead of just the one byte with a value of 153.
I am going to dive into the System.Text namespace, but
wanted to see if I could learn something here.

Really I have 2 questions:
1) How to append the actual byte to a stringbuilder
(byte2string function of somesort?)

2) How to properly determine the byte length of the
string. (sb.Length, sb.Capacity, sb.ToString
().SizeOf...???)

Thanks,
Tim.
 
I am close to a solution, maybe:

using:
ASCIIEncoding.GetString Method (Byte[])

will give me a string that represents an array of bytes.
However, there is a restriction:

"Any element of the bytes array that is greater than
hexadecimal 0x7F is translated to a Unicode question mark
('?')."

I need to use that extra bit. Also, assuming that I get
the proper string of bytes, what must I do to insure that
it doesn't get hacked up by the marshal?

Tim.
 
Hi,
[inline]

Tim said:
I am close to a solution, maybe:

using:
ASCIIEncoding.GetString Method (Byte[])

will give me a string that represents an array of bytes.
However, there is a restriction:

"Any element of the bytes array that is greater than
hexadecimal 0x7F is translated to a Unicode question mark
('?')."

I need to use that extra bit. Also, assuming that I get
the proper string of bytes, what must I do to insure that
it doesn't get hacked up by the marshal?

Tim.


-----Original Message-----
I am having problems using interop to call midiOutLongMsg.

in my MIDIHDR struct, i allocate MsgData as a string

I have been using a StringBuilder object to build MsgData
per byte. I am not getting the proper results, although
sometimes I do hear some notes being played, just not the
right ones...

What I think is happening is that when I do something like:

byte b=153;
Stringbuilder sb = new StringBuilder();
sb.Append(b);

i am appending the "string representation" of the byte.
ie "153" instead of just the one byte with a value of 153.
I am going to dive into the System.Text namespace, but
wanted to see if I could learn something here.

Really I have 2 questions:
1) How to append the actual byte to a stringbuilder
(byte2string function of somesort?)

Cast the byte to a char, like sb.Append ( (char) b), this will not change
the number.
There might be other ways though...
 
Back
Top