c# - FileDescriptora Missing Characters -
i using code found here drag-drop .msg files directly outlook. filedescriptora class implemented this:
[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; } and code file names is:
memorystream fgdstream = (memorystream)e.data.getdata("filegroupdescriptor"); byte[] fgdbytes = new byte[fgdstream.length]; fgdstream.read(fgdbytes, 0, fgdbytes.length); fgdstream.close(); //copy file group descriptor 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 pointer first file descriptor intptr fdptr = (intptr)((int)fgdapointer + marshal.sizeof(fgdapointer)); //loop number of files acording file group descriptor for(int fdindex = 0;fdindex < numfiles;fdindex++) { //marshal pointer file descriptor filedescriptora struct object fdobj = marshal.ptrtostructure(fdptr, typeof(nativemethods.filedescriptora)); nativemethods.filedescriptora fd = (nativemethods.filedescriptora)fdobj; //get file name of file descriptor , put in array filenames[fdindex] = fd.cfilename; //move file descriptor pointer next file descriptor fdptr = (intptr)((int)fdptr + marshal.sizeof(fd)); } this works great, except file name coming missing first couple characters. know cause and/or how fix it?
in comments on the codeproject page person mentions same problem - in case offset of array item computed start of structure, not taking account first 32/64 bits contain number of items in array:
[structlayout(layoutkind.sequential, charset = charset.ansi)] public sealed class filegroupdescriptora { public uint citems; public filedescriptora[] fgd; }
Comments
Post a Comment