mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-29 20:18:37 +08:00
Some comments on StringToPtrUTF8.
This commit is contained in:
parent
714caf4935
commit
7a1cf2b5fe
@ -20,8 +20,14 @@ namespace NTwain
|
|||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <param name="length">Actual number of bytes used to encode the string without the null.</param>
|
/// <param name="length">Actual number of bytes used to encode the string without the null.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static unsafe IntPtr StringToPtrUTF8(TWAIN twain, string value, out int length)
|
public static unsafe IntPtr StringToPtrUTF8(TWAIN twain, string value, out int length)
|
||||||
{
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
length = 0;
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
var utf8 = Encoding.UTF8;
|
var utf8 = Encoding.UTF8;
|
||||||
length = utf8.GetByteCount(value);
|
length = utf8.GetByteCount(value);
|
||||||
|
|
||||||
@ -32,6 +38,7 @@ namespace NTwain
|
|||||||
byte* bytes = (byte*)ptr;
|
byte* bytes = (byte*)ptr;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// fixed for managed pointer
|
||||||
fixed (char* firstChar = value)
|
fixed (char* firstChar = value)
|
||||||
{
|
{
|
||||||
written = Encoding.UTF8.GetBytes(firstChar, value.Length, bytes, length);
|
written = Encoding.UTF8.GetBytes(firstChar, value.Length, bytes, length);
|
||||||
|
Loading…
Reference in New Issue
Block a user