Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include <winnetwk.h>
#include <stdio.h>
HINSTANCE hInst;
LPNETRESOURCE network;
network->dwScope=RESOURCE_CONNECTED;
network->dwType=RESOURCETYPE_ANY;
network->dwDisplayType=RESOURCEDISPLAYTYPE_GENERIC;
network->dwUsage=RESOURCEUSAGE_CONNECTABLE;
network->lpLocalName=NULL;
network->lpRemoteName="\\\\192.168.0.4\\share";
network->lpComment="A connection for testing...";
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_BTN_DISABLE:
//SetCursorPos(0,0);
//mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); /* Left button down. */
//mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); /* Left button up. */
//Disable the EDITTEXT control
return TRUE;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
LPTSTR netprovnm;
unsigned long x;
char error_message[100];
DWORD data;
DWORD *bufsize;
*bufsize=100L;
data=WNetGetProviderName(0x10010000, netprovnm, bufsize);
if(data==ERROR_MORE_DATA)
{
MessageBox(HWND_DESKTOP, "Buffer size is too small for network\nprovider name. Trying again.", "Error", MB_OK | MB_ICONWARNING);
}
else if(data==ERROR_NO_NETWORK)
{
MessageBox(HWND_DESKTOP, "Network is not available.", "Error", MB_OK | MB_ICONERROR);
return 0;
}
else if(data==ERROR_INVALID_ADDRESS)
{
MessageBox(HWND_DESKTOP, "Invalid address.", "Error", MB_OK | MB_ICONERROR);
return 0;
}
else if(data==NO_ERROR)
{
network->lpProvider=netprovnm;
}
while(1) {
data=WNetAddConnection2(network, "", NULL, CONNECT_UPDATE_PROFILE);
if(data==NO_ERROR)
{
MessageBox(HWND_DESKTOP, "Successfully connected to network!", "Info", MB_OK);
}
else
{
x=data;
sprintf(error_message, "Error code: %d", x);
if(MessageBox(HWND_DESKTOP, error_message, "Error", MB_ABORTRETRYIGNORE | MB_ICONERROR | MB_DEFBUTTON2)!=IDRETRY)
{
break;
}
}
}
// The user interface is a modal dialog box
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
resource.h & resource.rc contain nothing of importance.