Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.9 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Sample.c
  5. Abstract:
  6. Command line test tool for calling the NwlibMakeNcp function.
  7. ***/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <ntddnwfs.h>
  15. #include <nwapi32.h>
  16. #include <ndsapi32.h>
  17. #include <nwxchg.h>
  18. //
  19. // Local structure definition
  20. //
  21. typedef struct _NWC_SERVER_INFO {
  22. HANDLE hConn ;
  23. UNICODE_STRING ServerString ;
  24. } NWC_SERVER_INFO, *PNWC_SERVER_INFO ;
  25. //
  26. // Main program function
  27. //
  28. int
  29. _cdecl main( int argc, char **argv )
  30. {
  31. NTSTATUS ntstatus = STATUS_SUCCESS;
  32. NWCCODE nwccode = SUCCESSFUL;
  33. NWCONN_HANDLE ConnectionHandle;
  34. OEM_STRING OemArg;
  35. UNICODE_STRING ServerName;
  36. UNICODE_STRING TreeName;
  37. WCHAR ServerNameBuffer[256];
  38. WCHAR TreeNameBuffer[48];
  39. BOOL fIsNds;
  40. PNWC_SERVER_INFO pServerInfo = NULL;
  41. if ( argc != 2 )
  42. {
  43. printf( "\nUsage: sample <NetWare server name>, not \\\\<server>\n" );
  44. system( "pause" );
  45. return -1;
  46. }
  47. OemArg.Length = strlen( argv[1] );
  48. OemArg.MaximumLength = OemArg.Length;
  49. OemArg.Buffer = argv[1];
  50. ServerName.Length = 0;
  51. ServerName.MaximumLength = sizeof( ServerNameBuffer );
  52. ServerName.Buffer = ServerNameBuffer;
  53. RtlOemStringToUnicodeString( &ServerName, &OemArg, FALSE );
  54. printf( "\nConnecting to NetWare server %S\n", ServerName.Buffer );
  55. nwccode = NWAttachToFileServerW( ServerName.Buffer,
  56. 0, // ScopeFlag - set to zero, not used
  57. &ConnectionHandle );
  58. if ( nwccode != SUCCESSFUL )
  59. {
  60. printf( "Error: Couldn't connect to NetWare server %S\n",
  61. ServerName.Buffer );
  62. printf( " NWAttachToFileServerW return ntstatus 0x%.8X\n\n",
  63. nwccode );
  64. return -1;
  65. }
  66. pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle;
  67. TreeName.Length = 0;
  68. TreeName.MaximumLength = sizeof( TreeNameBuffer );
  69. TreeName.Buffer = TreeNameBuffer;
  70. ntstatus = NwNdsIsNdsConnection( pServerInfo->hConn,
  71. &fIsNds,
  72. &TreeName );
  73. if ( ntstatus != STATUS_SUCCESS )
  74. {
  75. printf( "Error: NwNdsIsNdsConnection return ntstatus 0x%.8X\n\n",
  76. ntstatus );
  77. return -1;
  78. }
  79. if ( fIsNds )
  80. printf( "You are connected to tree %S\n", TreeName.Buffer );
  81. nwccode = NWDetachFromFileServer( ConnectionHandle );
  82. if ( nwccode != SUCCESSFUL )
  83. {
  84. printf( "Error: Couldn't disconnect from NetWare server %S\n",
  85. ServerName.Buffer );
  86. printf( " NWDetachFromFileServer return nwccode 0x%.8X\n\n",
  87. nwccode );
  88. return -1;
  89. }
  90. }