I have a function which allows the user to edit a file, either with their default program, or choose a program using SHOpenFileDialog()
.
I'm calling it by PInvoke in C# (https://www.pinvoke.net/default.aspx/shell32/SHOpenWithDialog.html):
[DllImport("shell32.dll", EntryPoint = "SHOpenWithDialog", CharSet = CharSet.Unicode)]
private static extern int SHOpenWithDialog(IntPtr hWndParent, ref tagOPENASINFO oOAI);
I call it with flags OAIF_HIDE_REGISTRATION | OAIF_EXEC
.
Under Windows 7, it returns 1 on success. Under Windows 10, it returns 0 on success. The documentation claims it returns S_OK
, which is 0, but that page was created on 2018/12/05, so I don't know what the previous documentation for it said.
What is the correct way to check the return code? Should I be checking for either 0 or 1 return value? Or should I be checking the Environment.OSVersion
and checking for different return codes based on the OS version? Can it ever returns 1 under Windows 10 as an error condition?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…