Since you already know the name of the Sketch (you are using it in SelectByID2), you can simply use PartDoc::FeatureByName("Sketch3") to get the feature object and then use feature.getSpecificFeature2() to get the underlying Sketch object.
In your case, you can simply use Feature::Select2() to select the feature and ModelDoc::EditSketch() to edit the sketch.
Hope it helps!!!
Thanks for your reply and that helps me a lot. I always try not using the obsolete APIs because I don't know whether they will cause something unexpected.
Now I found the problem in my code. The string argument in my function should be BSTR. Although use L"XXXX" can initialize the string, that is not a correct way.
Using the constructor by CComBSTR can solve the problem.
Your suggestion offers me a better way. Thx!