Path: news.mitre.org!blanket.mitre.org!agate!hammer.uoregon.edu!arclight.uoregon.edu!news.ibm.net.il!ibm.net!not-for-mail From: vampire@cross.garlic ((vampire)) Newsgroups: comp.os.ms-windows.programmer.nt.kernel-mode Subject: Re: Retrieve name of a device object Date: Sun, 02 Nov 1997 07:17:41 GMT Organization: Unspecified Organization Lines: 36 Message-ID: <345c285a.237690721@news.ibm.net.il> References: <345a3eb4.11883787@news.iaehv.nl> <345AC565.7A71@ftp.com> NNTP-Posting-Host: cirithungol.memco.co.il X-Newsreader: Forte Free Agent 1.1/32.230 >OBJECT_NAME_INFORMATION is (accidentally?) defined in NTDDK.H >and is actually a UNICODE_STRING: > >typedef struct _OBJECT_NAME_INFORMATION { > UNICODE_STRING Name; >} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; > >Given a device object, this function seems to return its >original device name (even though the device may be opened >through a symbolic link). At least I was able to translate >a COM port device object into \Device\SerialX name. The code >looked like this: > >char Buffer[256]; >NTSTATUS ObStatus; >ULONG ReturnLength = 0; >OBJECT_NAME_INFORMATION * Info = (OBJECT_NAME_INFORMATION *)Buffer; >RtlZeroMemory(Info, sizeof(OBJECT_NAME_INFORMATION)); >ObStatus = ObQueryNameString( Port->FileObject->DeviceObject, > Info, sizeof(Buffer), > &ReturnLength); >if ( NT_SUCCESS(ObStatus) && ReturnLength ) > if ( Info->Name.Length && Info->Name.Buffer ) > { > TRACE1("Device: %wZ\n",&Info->Name); > .......... > } > >Regards, >-Slava Watch out here. From my exprecience, you absolutely do not pass a PUNICODE as a parameter, but rather a pointer to a large buffer. The header of the buffer will be initialized (by the function) to a unicode string, with unicode.buffer pointing to the rest of the buffer.