Why do you keep ignoring everything? Keep it managed!
There is a very simple function somewhere in the framework that does what you want!
No need for messy conversion and interop between native.
After just a minute at msdn, I find this:
It's the same function in managed that you're trying to use native.