Investigating a GSCookie Corruption

GSCookie helps in finding buffer overrun cases on the stack and terminates the application when this is detected. In the .NET environment this would happen when calling into a native function when the function overrides the buffer on the stack corrupting the GSCookie put in place. Here is a similar case. I have a sample…

0

P/Invoke Marshal.StructuretoPtr

In this blog I am going to talk about Marshal.StructuretoPtr , especially its last parameter fDeleteOld. Although its msdn description is pretty concise but I have seen it to be a source of confusion a lot of times. Following is what it says: fDeleteOld Type: System..::.Booleantrue to have the Marshal..::.DestroyStructure method called on the ptr…

7

Floating point exception in managed code results in Access Violation crash

  Suppose you are calling some native code from your managed code, and you observe an Access Violation crash soon after returning from the native code inside your managed code. if you run the application inside the Visual Studio debugger you will see the following exceptions in the output window if IDE.   First-chance exception…

0

Troubleshooting PInvoke Related Issues

I am back with some more PInvoke Stuff.  Recently I was working on a PInvoke issue which I found interesting.  I have a C++ dll which has a function whose signature is int TestFunc(IN_STRUCT in_Params, RET_STRUCT * pret_Par).  I wanted to call this function from C#.  Function has two arguments.  First argument is input structure…

12

Marshalling Complicated Structures using PInvoke

This article talks about marshaling structures using PInvoke which has a pointer to an array of another structure as a member. When calling native functions in a managed application, a frequent question that comes to mind is how to marshal a nested complicated structure.  Recently I came across a scenario where we have to marshal…

3