Most likely, the problem is in the parameter
. This is a null pointer, and it's not possible to figure out what type do you imply, because there is more than one method named
, and this
can be interpreted as one or another type, because your
might mean any reference.
What to do? I don't know your declarations (please see my comment to the question; is it P/Invoked Windows API? Why?), but you need to use either array of bytes of the instance of
. Declare a variable of one and another type, initialize it with
and pass this explicitly defined variable to the method. This is a usual way of resolving such issues.
There are other problems in this code. You return the return result of this method, which is integer, but
However, you don't need that stuff at all
. Use the .NET class
and related classes, stop torturing yourself:
Answering a follow-up question:
Cleaning the registry is not easy and not safe. I would start from finding a good registry repair program. And such program should be the one which can backup all the registry and restore it. As you can screw up the registry to the point where you cannot boot or normally operate your OS, this repair program should boot its own OS from a flash drive or something.
I don't know what exactly to use but 100% sure this is possible. I would start looking from here:
It's hard to say where to start with the registry clean up. I have tried only a limited subset of cleaning. For example, you can locate all references to file system objects and detect those pointing to non-existing files/directories. These entries should be eventually removed, but first, you need to walk the registry to remove the entries where the entries you would remove are used and do it all recursively. Again, this is not easy and not safe. Thoroughly plan each step and theoretically calculate possible adverse effects, back up…
Sorry, probably I did not get it: if you not going to modify the registry, you are safe. Anyway, I hope the notes of [EDIT #1] could be useful.