jaredpar's WebLog

Code, rants and ramblings of a programmer.

Browse by Tags

Tagged Content List
  • Blog Post: Properly Incrementing an IntPtr

    Just as native pointer types are moved around with pointer arithmetic in native code, it can also be useful to move IntPtr types around in managed code.  Say for instance there is an IntPtr available which points to a native array of Dog instances.  To access the values of that array individually...
  • Blog Post: Dereference a double IntPtr

    A common PInvoke question is how to deal with a double pointer.  More specifically, how can one dereference an IntPtr to another pointer without using unsafe code?  Dereferencing a double pointer is done the same way a dereference to any other structure is done: Marshal.PtrToStructure . ...
  • Blog Post: Is IntPtr(long) truncating?

    The short answer is: No, not when it matters A colleague and I were discussing a particular scenario around IntPtr,PInvoke and 64 bit correctness.  Eventually our discussion lead us to the IntPtr constructor which takes a long.  To my surprise the code for the constructor is the following....
  • Blog Post: PInvoke and bool (or should I say BOOL)?

    Boolean value types are a constant source of problems for people attempting to generate PInvoke signatures. It's yet another case of managed and native types differing on size. There are two common boolean types in native code: bool and BOOL. As with most PInvoke issue the main issue is to understand...
  • Blog Post: When is a LONG not a long?

    Answer: When PInvoke is involved. I ran across a common error today on stackoverflow regarding P/Invoke that is worth blogging about. The question regarded the translation of a native API with a parameter of type LONG. The user mistakenly used the .Net long type as the parameter. The error is that...
  • Blog Post: PInvoke Interop Assistant on Channel 9

    Beth Massi dropped by my office a couple of months ago and we did a channel 9 video on the PInvoke Interop Assistant .  Mainly an overview of the product and a bit of a tutorial.  Check out the video here. http://channel9.msdn.com/posts/funkyonex/The-P-Invoke-Interop-Assistant/
  • Blog Post: PInvoke Interop Assistant now on CodePlex

    I'm happy to announce that the PInvoke Interop Assistant tool is now available on CodePlex.  This includes the binaries, source code and the dev authored unit tests.  It is hosted on the more general CLR Interop Tools page.  http://www.codeplex.com/clrinterop I will be actively maintaining...
  • Blog Post: Making PInvoke Easy

    I very excited to announce we recently released a tool I've been working on to MSDN that will greatly help with using PInvoke in managed code. The tool is called the "PInvoke Interop Assistant" and is included as part of a MSDN article on marshalling data for PInvoke and Reverse PInvoke scenarios. Here...
  • Blog Post: Follow up: PInvoke with 32 and 64 bit

    Recently after I made my original post titled “PInvoke with 32 and 64 bit”, a developer emailed me. They pointed out that there is an internal structure that dynamically resizes based on the architecture; IntPtr. IntPtr will be size of the native chip pointer value. So for values like size_t that map...
  • Blog Post: Marshaling Nested Data Structures Part 4

    This is part 4 of a series. You can find part one here . Please refer to that article for all of the Native definitions of the structures that I use here. In the previous article we were left with a solution where using the code was very clean but the actualy implementation had extra allocation and...
  • Blog Post: Marshaling Nested Data Structures Part 3

    This is part 3 of a series. You can find part one here . Please refer to that article for all of the Native definitions of the structures that I use here. In part 2 of this series I demonstrated how you can Marshal nested data structures by flattening an array of structures into it's individual elements...
  • Blog Post: Marshaling Nested Data Structures Part 2

    This is part 2 of a series. You can find part one here . Please refer to that article for all of the Native definitions of the structures that I use here. The most important thing to remember when Marshalling data is that the .Net Runtime really only cares about byte layout and how many bytes you...
  • Blog Post: Marshaling Nested Data Structures Part 1

    A frequent question that pops up on newsgroups such as microsoft.dotnet.framework.interop is how to Marshal nested structures (and arrays of nested structures) via P/Invoke. The documentation on the subject that I have found usually only covers structures that defined in the UnmanagedType enumeration...
  • Blog Post: Interop and Unions

    A frequent question I see pop up on news groups is how to create Unions in managed code for interop with P/Invoke. .NET does not directly support unions but you can use some Marshal magic to get them working. Take the following C union. union Foo { int a; float b; } Really what this...
Page 1 of 1 (14 items)