www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to convert C macro to D? Thanks.

reply FrankLike <1150015857 qq.com> writes:
Hi,everyone,

I can convert some simple C macros, but a bit more complicated 
will need your help.
For example:

#define _NDIS_CONTROL_CODE(request,method) \
             CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, 
method, FILE_ANY_ACCESS)

#define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, 
METHOD_OUT_DIRECT)

use alias or enum,how to do?

Thanks.
Feb 24 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 24 February 2018 at 13:50:16 UTC, FrankLike wrote:
 #define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, 
 METHOD_OUT_DIRECT)

 use alias or enum,how to do?
neither. those are little functions. auto IOCTL_NDIS_QUERY_GLOBAL_STATS () { return _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT); }
Feb 24 2018
parent FrankLike <1150015857 qq.com> writes:
On Saturday, 24 February 2018 at 13:57:27 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 24 February 2018 at 13:50:16 UTC, FrankLike wrote:
 #define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, 
 METHOD_OUT_DIRECT)
 auto IOCTL_NDIS_QUERY_GLOBAL_STATS () {
   return _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT);
 }
Sorry. I look for 'IOCTL_DISK_GET_DRIVE_GEOMETRY' in core.sys.windows.winioctl.d,then I know : enum :DWORD IOCTL_NDIS_QUERY_GLOBAL_STATS = CTL_CODE_T!(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS); It's ok. Thank you.
Feb 24 2018