本文介绍了如何转换“字符串* 128" VB6到C#代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VB6的类型用户,如下所示:

I have a type-user of VB6 as follows:

Private Type OSVERSIONINFO
    dwOSVersionInfoSize             As Long
    dwMajorVersion                  As Long
    dwMinorVersion                  As Long
    dwBuildNumber                   As Long
    dwPlatformId                    As Long
    szCSDVersion                    As String * 128
End Type



我无法在 [ ^ ],则报告错误.在该类型中,它包含"szCSDVersion"成员,该成员是具有128个空格的字符串缓冲区;请帮助我将其全部转换为C#代码.谢谢.



I can''t convert all that codes to C# code (i think it is the same a struct in C#) at http://www.developerfusion.com/tools/convert/vb-to-csharp/[^], it reports an error. In that type it contains "szCSDVersion" member which is a string buffer with 128 spaces; please help me convert all to C# code. Thanks.

推荐答案

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
   private string szcsdversion = string.Empty.PadLeft(128);
   public long dwOSVersionInfoSize;
   public long dwMajorVersion;
   public long dwMinorVersion;
   public long dwBuildNumber;
   public long dwPlatformId;
   public string szCSDVersion
   {
     get {return szcsdversion;}
     set {szcsdversion = value.PadLeft(128);}
   }
}


[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct OSVERSIONINFO
{
    public int dwOSVersionInfoSize;
    public int dwMajorVersion;
    public int dwMinorVersion;
    public int dwBuildNumber;
    public int dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string szCSDVersion;
}





[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OSVERSIONINFO
{
    public int dwOSVersionInfoSize;
    public int dwMajorVersion;
    public int dwMinorVersion;
    public int dwBuildNumber;
    public int dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string szCSDVersion;
}



您需要包括 System.Runtime.InteropServices 命名空间.



You need to include the System.Runtime.InteropServices namespace.


这篇关于如何转换“字符串* 128" VB6到C#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 20:51
查看更多