You absolutely don't need to mix native code with .NET code the way you do. Pure .NET code would be more than enough. It looks like you're using your old native-code habits in the world of .NET you are not really familiar with. I would suggest you start from scratch using .NET only.
[EDIT #1]
OK, here is a pattern for using a button. Suppose you have created a button
MyButton
somewhere and it is already appears on your Form or a Window. Now, how to make it clickable? Here:
myButton.Click += (sender, eventArgs) => {
SomeMethodToBeCalledOnMyButtonClick();
}
void SomeMethodToBeCalledOnMyButtonClick() { }
The button starts to respond to the user's click as soon as the above '+=' operator is executed. You can add more than one handler, which is important in certain cases. You can call the code with this operator, say, in your constructor after all controls are setup. Now, you can write any code withing the '{}' of this anonymous event handler. But in many cases calling just one separate method like
SomeMethodToBeCalledOnMyButtonClick
is better. Why? Because sometimes you need to call the same method from some other place (for example, a menu or whatever else). This method is free from the parameters passed in event handler (
sender, eventArgs
) and can be called from anywhere.
In other case, you may call the same method from the handlers of other controls or create a handler as a named method and add it to different controls. In this case, you will need to parametrize the handle using the one or both of parameters mentioned above.
[EDIT #2]
Perhaps I did not understand you; and you want something very different: to "click" a button on CCLEANER.EXE. If so, I have to say: this is a bad task which I do not recommend to solve at all: you won't get reliable results. It's better to create your own registry cleaner, otherwise you let the user to do it. The application is not designed to be "automated" this way, just don't do it.
—SA