将 VB6 类型转换为 C# 结构
Converting VB6 Type to C# struct
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
这是我原来的VB6代码,转换后的C#代码是
public struct WIN32_FIND_DATA
{
long dwFileAttributes;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
long nFileSizeHigh;
long nFileSizeLow;
long dwReserved0;
long dwReserved1;
cFileName As String * max_path;
cAlternate As String * 14
}
如何将 cFileName As String * max_path
转换为 C#
您似乎想要 编组 这个 struct
(例如调用 FindFirstFileEx
、FindNextFile
API 函数时) ;如果是你的情况
using System.Runtime.InteropServices;
...
[StructLayout(LayoutKind.Sequential)]
struct WIN32_FIND_DATA
{
public uint dwFileAttributes;
public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
public uint nFileSizeHigh;
public uint nFileSizeLow;
public uint dwReserved0;
public uint dwReserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] // MAX_PATH = 260
public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string cAlternateFileName;
}
有关详细信息,请参阅原始 WIN32_FIND_DATA 声明
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
这是我原来的VB6代码,转换后的C#代码是
public struct WIN32_FIND_DATA
{
long dwFileAttributes;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
long nFileSizeHigh;
long nFileSizeLow;
long dwReserved0;
long dwReserved1;
cFileName As String * max_path;
cAlternate As String * 14
}
如何将 cFileName As String * max_path
转换为 C#
您似乎想要 编组 这个 struct
(例如调用 FindFirstFileEx
、FindNextFile
API 函数时) ;如果是你的情况
using System.Runtime.InteropServices;
...
[StructLayout(LayoutKind.Sequential)]
struct WIN32_FIND_DATA
{
public uint dwFileAttributes;
public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
public uint nFileSizeHigh;
public uint nFileSizeLow;
public uint dwReserved0;
public uint dwReserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] // MAX_PATH = 260
public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string cAlternateFileName;
}
有关详细信息,请参阅原始 WIN32_FIND_DATA 声明