I'm writing a VC++/CLI
<-> C#
interface for a small unmanaged library. This library uses and implements WINAPI methods, so it mainly uses constructs as
DWORD getResult(__out LPWSTR* result);
Which means it does not return the requested result, but a statuscode, and the requested result is passed in the output parameter.
In C#, it seems, I have (at least) two ways of writing the interface:
- Dumbly "transpile" it to
UInt32 getResult(String^% result);
- Make the interface more "object-oriented" by writing the method like
String^ getResult();
throwing an (e.g.)Win32Exception
when the statuscode of the managed call is non-zero (wrapping the statuscode in itsNativeErrorCode
member) (as shown e.g. here: Throwing a Win32Exception )
Of course this would not be that simple in case of multi-output functions, but let's say I don't care about them.
As I'm more used to OOP than to the VC++ style of coding, I would prefer option 2. However, I'm not sure if there aren't reasons that would render that a bad design choice (or if there isn't a third, even better way).