Подключаем сетевой диск под Windows NT
Источник: www.исходники.ru
Небольшой пример, демонстрирующий использование WIN32 Security API в ассемблере. В частности показывается, как подключить или отключить сетевой диск.
Компилятор: MASM32
Ниже приведён исходный код программы:
.386 .model flat,stdcall option casemap:none WinMain proto :DWORD,:DWORD,:DWORD,:DWORD include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\mpr.inc includelib \masm32\lib\mpr.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib .data ClassName db "SimpleWinClass",0 AppName db "NT Security API In Assembly !",0 ButtonClassName db "button",0 ButtonConnectText db "Map Drive",0 ButtonDisconnectText db "Un-Map Drive",0 .data? hwndConnectButton HWND ? hwndDisconnectButton HWND ? hInstance HINSTANCE ? CommandLine LPSTR ? .const IDM_GETTEXT equ 1 ButtonConnectID equ 2 ButtonDisconnectID equ 3 .code start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hwnd:HWND mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInst pop wc.hInstance mov wc.hbrBackground,COLOR_BTNFACE+1 mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ CW_USEDEFAULT,540,305,NULL,NULL,\ hInst,NULL mov hwnd,eax INVOKE ShowWindow, hwnd,SW_SHOWNORMAL INVOKE UpdateWindow, hwnd .WHILE TRUE INVOKE GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) INVOKE TranslateMessage, ADDR msg INVOKE DispatchMessage, ADDR msg .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM .IF uMsg==WM_DESTROY invoke PostQuitMessage,NULL .ELSEIF uMsg==WM_CREATE invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonConnectText,\ WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\ 122,80,100,25,hWnd,ButtonConnectID,hInstance,NULL mov hwndConnectButton,eax invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonDisconnectText,\ WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\ 122,120,100,25,hWnd,ButtonDisconnectID,hInstance,NULL mov hwndDisconnectButton,eax .ELSEIF uMsg==WM_COMMAND mov eax,wParam .IF ax==ButtonConnectID shr eax,16 .IF ax==BN_CLICKED invoke WNetConnectionDialog,hWnd,RESOURCETYPE_DISK .ENDIF .ENDIF .IF ax==ButtonDisconnectID shr eax,16 .IF ax==BN_CLICKED invoke WNetDisconnectDialog,hWnd,RESOURCETYPE_DISK .ENDIF .ENDIF .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp end start