分类: WINDOWS
2005-10-17 16:00:04
第五节:确定一共享的位置
下面的例子演示了怎样使用WNetGetUniversalName函数来确定在重定向设备的一共享文件的位置
可用C编译器对其进行编译,但要加上SHELL32.LIB,MPR.LIB,NETAPI32库
//用GetUni H:
#define STRICT
#include
#include
#define BUFFSIZE = 1000
void main( int argc, char *argv[] )
{
DWORD cbBuff = 1000 //缓冲大小
TCHAR szBuff[1000]; //接收消息的缓冲
REMOTE_NAME_INFO * prni = (REMOTE_NAME_INFO *) &szBuff;
//指向缓冲的头部
UNIVERSAL_NAME_INFO * puni = (UNIVERSAL_NAME_INFO *) &szBuff;
DWORD res;
if((argc < 2) | (lstrcmp(argv[1], "/?") == 0))
{
printf("语法: GetUni 设备路经和文件名
"
"例子: GetUni U:\WINNT\SYSTEM32\WSOCK32.DLL
");
return;
}
//调用WNetGetUniversalName 使用 UNIVERSAL_NAME_INFO_LEVEL 指令
printf("调用 WNetGetUniversalName 使用 UNIVERSAL_NAME_INFO_LEVEL.
");
if((res = WNetGetUniversalName((LPTSTR)argv[1],
UNIVERSAL_NAME_INFO_LEVEL,
(LPVOID) &szBuff, //接收此机构的缓冲
&cbBuff)) != NO_ERROR) //of memory
printf("Error: %ld
", res); //出错
else
printf("Universal Name: %s
", //输出结果
puni->lpUniversalName); //指针指向 REMOTE_NAME_INFO_LEVEL 结构
//也可用REMOTE_NAME_INFO_LEVEL指令
printf("调用WNetGetUniversalName使用REMOTE_NAME_INFO_LEVEL.
");
if((res = WNetGetUniversalName((LPTSTR)argv[1],
REMOTE_NAME_INFO_LEVEL,
(LPVOID) &szBuff, //接收此机构的缓冲
&cbBuff)) != NO_ERROR)
printf("Error: %ld
", res); //出错输出错误
else
printf("Universal Name: %s
" //输出结果
"Connection Name: %s
" //指针指向 REMOTE_NAME_INFO_LEVEL结构
"Remaining Path: %s
",
prni->lpUniversalName,
prni->lpConnectionName,
prni->lpRemainingPath);
return;
}
;====汇编语言描述(BY 谢小荣)=====
include masm32includeMPR.inc
include masm32include
etapi32.inc
includelib masm32libMPR.lib
includelib masm32lib
etapi32.lib
AsmWNetGetUniversalName PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
szBuff db 1000 dup(0)
msg_err1 db "有错!",0
.code
AsmWNetGetUniversalName proc hwnd:DWORD,hdc:DWORD,hdc2:DWORD,lpPath:DWORD
invoke WNetGetUniversalName,lpPath,UNIVERSAL_NAME_INFO_LEVEL,addr szBuff,1000
.IF EAX==NO_ERROR
invoke TextOut,hdc, 10, 10, addr szBuff, 80
.ESLE
invoke TextOut,hdc, 10, 10, addr msg_err1, 10
.ENDIF
invoke WNetGetUniversalName,lpPath,REMOTE_NAME_INFO_LEVEL,addr szBuff,1000
.IF EAX==NO_ERROR
push esi
mov esi,offset szBuff
assume [esi]:REMOTE_NAME_INFO
invoke TextOut,hdc2, 10, 10, addr [esi].lpUniversalName, 1000
invoke TextOut,hdc2,10,10,addr [esi].lpConnectionName,1000
assume [esi]:nothing
.ELSE
invoke TextOut,hdc2, 10, 10, addr msg_err1, 10
.ENDIF
ret
AsmWNetGetUniversalName endp