007
11.03.2004, 15:51 Uhr
Tody
|
Hi mein Programm lässt sich ohne Probleme kompilieren aber stellt keine Verbindung her. Ich weiß nich woran es liegt. Es landet immer in der default-Meldung.
Hier der komplette Code:
C++: |
#include <stdio.h> #include <tchar.h> #include <windows.h> #include <winnetwk.h>
int _tmain(int argc, _TCHAR* argv[]) { TCHAR local[32] = "Q:"; TCHAR res[MAX_PATH] = "\\\\192.168.99.33\\freigabe$"; TCHAR user[32] = "user"; TCHAR pass[32] = "password"; NETRESOURCE netresource;
netresource.dwType = RESOURCETYPE_ANY; netresource.lpLocalName = local; netresource.lpRemoteName = res; netresource.lpProvider = NULL;
DWORD err = WNetAddConnection2( &netresource, // points to structure that specifies connection details pass, // points to password string user, // points to user name string FALSE); // set of bit flags that specify // connection options
if (err == NO_ERROR) {
MessageBox(NULL, "Verbunden", "", MB_OK);
// Aktion
err = WNetCancelConnection2( local, // pointer to resource name to disconnect 0, // connection type flags 1); // flag for unconditional disconnect
if (err == NO_ERROR) { MessageBox(NULL, "Getrennt", "", MB_OK); } else { MessageBox(NULL, "Fehler beim Trennen", "", MB_OK); }
} else { switch (err) { case ERROR_ACCESS_DENIED: MessageBox(NULL, "Access denied", "", MB_OK); break; case ERROR_ALREADY_ASSIGNED: MessageBox(NULL, "Already assigned", "", MB_OK); break; case ERROR_BAD_DEV_TYPE: MessageBox(NULL, "Bad Dev Type", "", MB_OK); break; case ERROR_BAD_DEVICE: MessageBox(NULL, "Bad Device", "", MB_OK); break; case ERROR_BAD_NET_NAME: MessageBox(NULL, "Bad Net Name", "", MB_OK); break; case ERROR_BAD_PROFILE: MessageBox(NULL, "Bad Profile", "", MB_OK); break; case ERROR_BAD_PROVIDER: MessageBox(NULL, "Bad Provider", "", MB_OK); break; case ERROR_BUSY: MessageBox(NULL, "Busy", "", MB_OK); break; case ERROR_CANCELLED: MessageBox(NULL, "Canceled", "", MB_OK); break; case ERROR_CANNOT_OPEN_PROFILE: MessageBox(NULL, "Cannot open Profile", "", MB_OK); break; case ERROR_DEVICE_ALREADY_REMEMBERED: MessageBox(NULL, "Device already remembered", "", MB_OK); break; case ERROR_EXTENDED_ERROR: MessageBox(NULL, "Extended Error", "", MB_OK); break; case ERROR_INVALID_PASSWORD: MessageBox(NULL, "Invalid Password", "", MB_OK); break; case ERROR_NO_NET_OR_BAD_PATH: MessageBox(NULL, "No Net or bad Path", "", MB_OK); break; case ERROR_NO_NETWORK: MessageBox(NULL, "No Network", "", MB_OK); break; default: MessageBox(NULL, "Error", "", MB_OK); } }
return 0; }
|
|