How? With extreme difficulty. C# is not an appropriate language to do this in.
You can find a sample of an IME
here[
^]. It's written in C++ for a reason. Because of how close you have to get to Windows and the complexity of the interaction with the SDK, it's best to write an IME in C or C++.
If you attempt this in C#, you'll end up rewriting a bunch of the SDK in C#, thereby increasing the amount of work you have to do.