public String DsMakeSpn ( String serviceClass , String serviceName , String instanceName , short instancePort , String referrer ) throws LastErrorException { IntByReference spnLength = new IntByReference ( 2048 ) ; char [ ] spn = new char [ spnLength . getValue ( ) ] ; final int ret = NTDSAPI . instance . DsMakeSpnW ( new WString ( serviceClass ) , new WString ( serviceName ) , instanceName == null ? null : new WString ( instanceName ) , instancePort , referrer == null ? null : new WString ( referrer ) , spnLength , spn ) ; if ( ret != NTDSAPI . ERROR_SUCCESS ) { /* Should've thrown LastErrorException, but just in case */ throw new RuntimeException ( "NTDSAPI DsMakeSpn call failed with " + ret ) ; } return new String ( spn , 0 , spnLength . getValue ( ) ) ; }
Convenience wrapper for NTDSAPI DsMakeSpn with Java friendly string and exception handling .