Я использую найденный код here для перетаскивания файлов .msg непосредственно из Outlook. FileDescriptorA
класса реализуются следующим образом:FileDescriptora Отсутствующие символы
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class FILEDESCRIPTORA
{
public uint dwFlags;
public Guid clsid;
public SIZEL sizel;
public POINTL pointl;
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;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string cFileName;
}
И код, чтобы получить имена файлов является:
MemoryStream fgdStream =
(MemoryStream)e.Data.GetData("FileGroupDescriptor");
byte[] fgdBytes = new byte[fgdStream.Length];
fgdStream.Read(fgdBytes, 0, fgdBytes.Length);
fgdStream.Close();
//copy the file group descriptor into unmanaged memory
IntPtr fgdaPtr = Marshal.AllocHGlobal(fgdBytes.Length);
Marshal.Copy(fgdBytes, 0, fgdaPtr, fgdBytes.Length);
int numFiles = Marshal.ReadInt32(fgdaPtr);
string[] fileNames = new string[numFiles];
//get the pointer to the first file descriptor
IntPtr fdPtr = (IntPtr)((int)fgdaPointer + Marshal.SizeOf(fgdaPointer));
//loop for the number of files acording to the file group descriptor
for(int fdIndex = 0;fdIndex < numfiles;fdIndex++)
{
//marshal the pointer to the file descriptor as a FILEDESCRIPTORA struct
object fdObj = Marshal.PtrToStructure(fdPtr,
typeof(NativeMethods.FILEDESCRIPTORA));
NativeMethods.FILEDESCRIPTORA fd = (NativeMethods.FILEDESCRIPTORA)fdObj;
//get file name of file descriptor and put in array
fileNames[fdIndex] = fd.cFileName;
//move the file descriptor pointer to the next file descriptor
fdPtr = (IntPtr)((int)fdPtr + Marshal.SizeOf(fd));
}
Это все работает отлично, за исключением того, что имя файла возвращается всегда отсутствует первый пара символов. Кто-нибудь знает, что может вызвать это и/или как его исправить?
На этой странице кодекса есть комментарий другого человека, имеющего эту проблему и возможное решение, вы проверили это? –
@ C.Evenhuis Я пробовал это, и это не помогло. Для меня есть 2 недостающих персонажа, а не 4. – pquest
@ C.Evenhuis неважно, это все еще моя проблема. Я исправил блок 'FileGroupDescriptorA', но не блок' FileGroupDescriptorW'. Если вы хотите разместить содержание этих комментариев в ответе, я был бы рад отметить его как правильный. – pquest