If you already spotted the bug, well done.Įssentially, the problem was that I was using WriteInt16 instead of WriteByte, due to an IntelliSense-aided typo, resulting in the final iteration writing one byte over the end of the buffer. In reality there's some other stuff going off in here, related to native resource tracking, but that's basically it. IntPtr ptrToMem = Marshal.AllocHGlobal(bufferSize) Here's a simplification of the offending code: IntPtr AllocBlock(int bufferSize) Yes, it's ugly, but the alternative is COM. Already I can tell you're feeling nauseous, so I won't go into any more detail. ![]() One of these C# methods has to pass back a struct to Delphi, where it's cast to a record. ![]() I've got a C# DLL which exports some native methods (via this awesome project template) which are then called by a Delphi application. I just spent the last hour tackling a bizarre issue with unmanaged memory in C#.įirst, a bit of context.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |