HOWTO: Open TCP and UDP from Win32 Applications |
Q195316
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().
The following sample code demonstrates how to open the TCP device object:
#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 kbOSWinNT310 kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin2000
Issue type : kbhowto
Technology : kbAudDeveloper kbWinDDKSearch kbWin32sSearch kbWin32DDKSearch kbWin32DDKNT310 kbWin32DDKNT350 kbWin32DDKNT351 kbWin32DDKNT400 kbWin32DDKNTSearch
|
Last Reviewed: March 10, 1999 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |