HOWTO: Open TCP and UDP from Win32 Applications

ID: Q195316


The information in this article applies to:
  • Microsoft Win32 Device Driver Kit (DDK) for Windows NT, versions 3.1, 3.5, 3.51, 4.0, 5.0


SUMMARY

You might want to enable your Win32 application to open the UDP or TCP device objects. By doing this, you enable the application to open a TDI control channel to UDP or TCP. By default, there is no symbolic links created to TCP or UDP. The Win32 application must call DefineDosDevice to create a symbolic link before calling CreateFile().


MORE INFORMATION

The following sample code demonstrates how to open the TCP device object:

Sample Code


   #include <windows.h>

   void main()
   {
   HANDLE  handle = NULL;
   BOOL      success = NULL;
   char    deviceName[] = "TCP";
   char    targetPath[] = "\\Device\\TCP";
   char    completeDeviceName[] = "\\\\.\\TCP";

   // 
   // First create a symbolic link.
   // 

   success = DefineDosDevice (DDD_RAW_TARGET_PATH,
                    deviceName,
               targetPath
               );

   if (!success) {
   MessageBox(NULL,"DefineDosDevice failed","Notice",MB_OK);
   }

   // 
   // Then call CreateFile().
   // 

   handle = CreateFile(completeDeviceName,
             GENERIC_READ | GENERIC_WRITE,
             0,
             NULL,
             OPEN_EXISTING,
             FILE_ATTRIBUTE_NORMAL,
             NULL
             );

   if (handle == INVALID_HANDLE_VALUE) {
      MessageBox(NULL,"CreateFile failed","Notice",MB_OK);
   } else {
      MessageBox(NULL,"CreateFile succeded","Notice",MB_OK);
      CloseHandle(handle);
   }
   } 

Keywords : kbDDK kbNDIS kbNTOS310 kbNTOS350 kbNTOS351 kbNTOS400 kbWinOS2000
Version :
Platform :
Issue type : kbhowto


Last Reviewed: March 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.