WARNING: VS 2012 might break your broken P/Invoke

I’m seeing many people reporting that they are seeing strange P/invoke issues when they moved their code to VS 2012. Typically, they have P/invokes like this: [DllImport("Win32Project2.dll", PreserveSig = true, CharSet = CharSet.Unicode)] static extern int MyPInvoke(out string ret); If you attach a native debugger (or enable native debugging), with the right symbols (public symbol…

2

If your Windows Phone 7 doesn’t sync with Zune Software, try a different USB port

I recently got Samsung Focus but it doesn’t get recognized by the Zune Software – it says “No device connected”, even though my phone did ring a sound when it connects to my computer and zune software did pop up. Spend half hour searching for solutions and I run into this article: http://www.microsoft.com/windowsphone/en-us/howto/wp7/basics/the-zune-software-doesnt-recognize-my-phone.aspx One of…

1

C++ coroutine tutorial

I’ve been experimenting with coroutines recently and I found that information on C++ coroutines are very difficult to find. I’m planning to write a series of C++ coroutine blogs on how to use C++ coroutines, how they work, and how to write your own library that uses C++ coroutines. My last post Basic Concepts are…

1

Interpreting HRESULTS returned from .NET/CLR: 0x8013XXXX

What is 0x8013XXXX Occasionally you might run into mysterious HRESULTs returned from .NET that begins with 0x8013, for example, 0x80131522. Unfortunately the error lookup shipped with Visual Studio doesn’t really work on those strange HRESULTs. What are they? It turns out they are in fact, defined by .NET/CLR in the header files. All these failure/success…

0

Writing your own lock-free reader/writer lock

It is sort of puzzling for me why C++ standard doesn’t have a implementation of reader/writer lock. So just like every other C++ developer, I’ve decided to roll my own.  A typical implementation might be using semaphore / mutex. However, this has a major disadvantage that it requires entering a lock mutex every time a…

0

Calling node.js sqlite callback function using promise and await

Callback pain I was experimenting with sqlite package with node.js the other day and the async programming style is rather painful, so I did some experiment to wrap it with promise + async/await to make it easier to use. This post shows you how to do that. For example, let’s say I’m working with a database with…

0

Calling C functions from Python – part 1 – using ctypes

Recently I’ve been evaluating Python interop technologies for a project at work and I think it’ll made an interesting blog series. Let’s say your have following C code (add extern “C” if you are in C++ land) and compile it into a dynamic library (dll/.so/.dylib): int Print(const char *msg) { printf(“%s”, msg); return 0; } int Add(int…

0

Calling C functions from Python – part 2 – writing CPython extensions using Python/C API

In my previous post we’ve briefly looked at using ctypes module to call C APIs. In this post let’s dive into a completely different approach – writing a C extension using Python/C API. From the C extension you can then call whatever C/C++ code you want. This is a pretty popular approach to expose a 3rd party…

0

Calling C functions from Python – part 3 – deep dive into ctypes implementation in CPython

Last time we’ve looked at using ctypes to call C API, and writing extension module using Python/C API. Now we can finally tie these two together – looking at how ctypes is actually implemented using mix of Python/C API and Python code. You can find CPython source code here. ctypes’ C implementation is here ctypes’ python implementation…

0

Sharing .NET generic code under the hood

If you come from a C++ programming background, you are most likely already familiar with C++’s template code bloat problem. Each template instantiation gets its own copy of the code (of course, compiler/linker can optimize by throwing away unused methods). The reason being that C++ template are more like C macro on steriods. I know…

0