Template: get function name
novice3
sorryno at em.ail
Mon Aug 17 08:07:32 UTC 2020
Hello.
I have wrapping Windows API functions, wich return 0 on success
and erroro code on failure.
I copy wenforce template as:
```
private T denforce(T, S)(T value, lazy S msg = null, string file
= __FILE__, size_t line = __LINE__)
{
import core.sys.windows.winerror: NO_ERROR;
import std.conv: to;
if (value != NO_ERROR)
throw new WindowsException(value, to!string(msg), file, line);
return value;
}
```
and use it:
```
DhcpEnumServers(0, null, servers, null,
null).denforce("DhcpEnumServers");
````
Then windows api - extern (Windows)DhcpEnumServers - return
error, then Windows exception throwed with name of failed api
"DhcpEnumServers".
Can we change template to avoid api name dublicate?
Can denforce template obtain "DhcpEnumServers" function name to
format message "DhcpEnumServers api failed"?
Thanks.
More information about the Digitalmars-d-learn
mailing list