The API function DSGetDCName() is a recommended way to obtain the domain controller name by domain name etc.
Calling this function one should take care about combination of used flag combination: this is mostly the point of optimization.
To let the developer experiment with the flags I’ve build a quick app helping to check different flag combinations:

Bits and source code are available on request or here.
Enjoy!