|
|
typedef DWORD
(__stdcall *LPFUNC_WNetEnumResourceA)(
HANDLE,
LPDWORD,
LPVOID,
LPDWORD
);
typedef DWORD
(__stdcall *LPFUNC_WNetCloseEnum)(
HANDLE
);
typedef DWORD
(__stdcall *LPFUNC_WNetOpenEnumA)(
DWORD,
DWORD,
DWORD,
LPNETRESOURCEA,
LPHANDLE
);
typedef DWORD
(__stdcall *LPFUNC_WNetDisconnectDialog)(
HWND hwnd,
DWORD dwType
);
typedef DWORD
(__stdcall *LPFUNC_WNetConnectionDialog1A)(
LPCONNECTDLGSTRUCTA lpConnDlgStruct
);
typedef DWORD
(__stdcall *LPFUNC_WNetCancelConnection2A)(
LPCSTR,
DWORD,
BOOL
);
typedef DWORD
(__stdcall *LPFUNC_WNetUseConnectionA)(
HWND,
LPNETRESOURCEA,
LPCSTR,
LPCSTR,
DWORD,
LPSTR,
LPDWORD,
LPDWORD
);
| |
|
|
|
|
// *********************************************************
// デフォルトコンストラクタ
// *********************************************************
LboxWNet::LboxWNet()
{
this->User.SetChar( 0, 0 );
this->Password.SetChar( 0, 0 );
this->AccessName.Resize( MAX_PATH );
this->lib = LoadLibrary( "mpr.dll" );
}
// *********************************************************
// デストラクタ
// *********************************************************
LboxWNet::~LboxWNet()
{
if ( this->lib != NULL ) {
FreeLibrary( this->lib );
}
}
| |
|
|
|
|
// *********************************************************
// ディスク資源接続
// 戻り値 : true 成功, false 失敗
// *********************************************************
// バッチ用-自動接続
BOOL LboxWNet::Connect( LboxString *LRemote, BOOL bKeep )
{
return LboxWNet::Connect(
LRemote->szLboxString,
bKeep
);
}
BOOL LboxWNet::Connect( LPTSTR lpRemote, BOOL bKeep )
{
return LboxWNet::Connect(
NULL,
lpRemote,
NULL,
false,
bKeep
);
}
// ログイン対話用-自動接続
BOOL LboxWNet::Connect( HWND hOwner, LboxString *LRemote, BOOL bKeep )
{
return LboxWNet::Connect(
hOwner,
LRemote->szLboxString,
bKeep
);
}
BOOL LboxWNet::Connect( HWND hOwner, LPTSTR lpRemote, BOOL bKeep )
{
return LboxWNet::Connect(
hOwner,
lpRemote,
NULL,
true,
bKeep
);
}
// バッチ用-デバイス指定接続
BOOL LboxWNet::Connect( LboxString *LRemote, LboxString *LLocal, BOOL bKeep )
{
return LboxWNet::Connect(
LRemote->szLboxString,
LLocal->szLboxString,
bKeep
);
}
BOOL LboxWNet::Connect( LPTSTR lpRemote, LPTSTR lpLocal, BOOL bKeep )
{
return LboxWNet::Connect(
NULL,
lpRemote,
lpLocal,
false,
bKeep
);
}
// ログイン対話用-デバイス指定接続
BOOL LboxWNet::Connect(
HWND hOwner, LboxString *LRemote, LboxString *LLocal, BOOL bKeep )
{
return LboxWNet::Connect(
hOwner,
LRemote->szLboxString,
LLocal->szLboxString,
bKeep
);
}
BOOL LboxWNet::Connect( HWND hOwner, LPTSTR lpRemote, LPTSTR lpLocal, BOOL bKeep )
{
return LboxWNet::Connect(
hOwner,
lpRemote,
lpLocal,
true,
bKeep
);
}
// 汎用
BOOL LboxWNet::Connect(
HWND hOwner, LboxString *LRemote, LboxString *LLocal, BOOL bPrompt, BOOL bKeep )
{
return LboxWNet::Connect(
hOwner,
LRemote->szLboxString,
LLocal->szLboxString,
bPrompt,
bKeep
);
}
BOOL LboxWNet::Connect(
HWND hOwner, LPTSTR lpRemote, LPTSTR lpLocal, BOOL bPrompt, BOOL bKeep )
{
if ( this->lib == NULL ) {
return false;
}
LPFUNC_WNetUseConnectionA DllWNetUseConnection;
DllWNetUseConnection =
(LPFUNC_WNetUseConnectionA)GetProcAddress( lib, "WNetUseConnectionA" );
if ( DllWNetUseConnection == NULL ) {
return false;
}
NETRESOURCE nr;
DWORD dwFlag;
DWORD dwSize;
DWORD dwResult;
DWORD dwRet;
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = lpLocal;
nr.lpRemoteName = lpRemote;
nr.lpProvider = NULL;
dwFlag = CONNECT_REDIRECT;
if ( bKeep ) {
dwFlag = dwFlag | CONNECT_UPDATE_PROFILE;
}
if ( bPrompt ) {
dwFlag = dwFlag | CONNECT_INTERACTIVE | CONNECT_PROMPT;
}
this->AccessName.SetChar( 0, 0 );
dwSize = this->AccessName.nLboxString;
dwResult = 0;
dwRet = DllWNetUseConnection(
hOwner,
&nr,
this->Password.szLboxString,
this->User.szLboxString,
dwFlag,
this->AccessName.szLboxString,
&dwSize,
&dwResult
);
this->ErrorDescription.SetChar( 0, 0 );
if ( dwRet == NO_ERROR ) {
return true;
}
switch( dwRet ) {
case ERROR_ACCESS_DENIED:
this->ErrorDescription.operator = (
"ネットワーク資源へのアクセスが拒否されました"
);
break;
case ERROR_ALREADY_ASSIGNED:
this->ErrorDescription.operator = (
"ローカルデバイスはすでにネットワーク資源に接続されています"
);
break;
case ERROR_BAD_DEVICE:
this->ErrorDescription.operator = (
"資源の名前が無効か、指定した名前の資源が見つかりません"
);
break;
case ERROR_BAD_PROVIDER:
this->ErrorDescription.operator = (
"指定したプロバイダが無効です"
);
break;
case ERROR_CANCELLED:
this->ErrorDescription.operator = (
"接続先の資源が接続操作を取り消しました"
);
break;
case ERROR_EXTENDED_ERROR:
this->ErrorDescription.operator = (
"ネットワーク固有のエラーが発生しました"
);
break;
case ERROR_INVALID_PARAMETER:
this->ErrorDescription.operator = (
"パラメータに誤りがあります"
);
break;
case ERROR_INVALID_PASSWORD:
this->ErrorDescription.operator = (
"指定したパスワードが無効です"
);
break;
case ERROR_MORE_DATA:
this->ErrorDescription.operator = (
"バッファが小さすぎます"
);
break;
case ERROR_NO_MORE_ITEMS:
this->ErrorDescription.operator = (
"有効なローカルデバイスがすべて使われています"
);
break;
case ERROR_NO_NET_OR_BAD_PATH:
this->ErrorDescription.operator = (
"ネットワークコンポーネントが開始されていません"
);
break;
case ERROR_NO_NETWORK:
this->ErrorDescription.operator = (
"ネットワークに接続されていません"
);
break;
}
return false;
}
| |
|
|
|
|
// 強制切断
BOOL LboxWNet::DisConnectForce(LboxString *LName, BOOL bKeep)
{
return LboxWNet::DisConnectForce(
LName->szLboxString,
bKeep
);
}
BOOL LboxWNet::DisConnectForce(LPTSTR lpName, BOOL bKeep)
{
return LboxWNet::DisConnect(
lpName,
bKeep,
true
);
}
| |
|
|
|
|
// 通常切断
BOOL LboxWNet::DisConnect(LboxString *LName, BOOL bKeep)
{
return LboxWNet::DisConnect(
LName->szLboxString,
bKeep
);
}
BOOL LboxWNet::DisConnect(LPTSTR lpName, BOOL bKeep)
{
return LboxWNet::DisConnect(
lpName,
bKeep,
false
);
}
// 汎用
BOOL LboxWNet::DisConnect(LboxString *LName, BOOL bKeep, BOOL bForce)
{
return LboxWNet::DisConnect(
LName->szLboxString,
bKeep,
bForce
);
}
BOOL LboxWNet::DisConnect(LPTSTR lpName, BOOL bKeep, BOOL bForce)
{
if ( this->lib == NULL ) {
return false;
}
LPFUNC_WNetCancelConnection2A DllWNetCancelConnection;
DllWNetCancelConnection =
(LPFUNC_WNetCancelConnection2A)GetProcAddress(
lib, "WNetCancelConnection2A"
);
if ( DllWNetCancelConnection == NULL ) {
return false;
}
DWORD dwRet;
DWORD dwKeep;
if ( bKeep ) {
dwKeep = 0;
}
else {
dwKeep = CONNECT_UPDATE_PROFILE;
}
dwRet = DllWNetCancelConnection(
lpName,
dwKeep,
bForce
);
this->ErrorDescription.SetChar( 0, 0 );
if ( dwRet == NO_ERROR ) {
return true;
}
switch( dwRet ) {
case ERROR_BAD_PROFILE:
this->ErrorDescription.operator = (
"ユーザープロファイルの形式が正しくありません"
);
break;
case ERROR_CANNOT_OPEN_PROFILE:
this->ErrorDescription.operator = (
"ユーザープロファイルを開くことができません"
);
break;
case ERROR_DEVICE_IN_USE:
this->ErrorDescription.operator = (
"デバイスがアクティブなプロセス"
"によって使用中のため切断できません"
);
break;
case ERROR_EXTENDED_ERROR:
this->ErrorDescription.operator = (
"ネットワーク固有のエラーが発生しました"
);
break;
case ERROR_NOT_CONNECTED:
this->ErrorDescription.operator = (
"デバイスが無効です"
);
break;
case ERROR_OPEN_FILES:
this->ErrorDescription.operator = (
"開いているファイルがあるので切断できません"
);
break;
}
return false;
}
| |
|
|
|
|
// *********************************************************
// ディスク資源ダイアログ接続
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWNet::DialogConnect( HWND hOwner )
{
if ( this->lib == NULL ) {
return false;
}
LPFUNC_WNetConnectionDialog1A DllWNetConnectionDialog;
DllWNetConnectionDialog =
(LPFUNC_WNetConnectionDialog1A)GetProcAddress(
lib, "WNetConnectionDialog1A"
);
if ( DllWNetConnectionDialog == NULL ) {
return false;
}
NETRESOURCE nr;
ZeroMemory( &nr, sizeof(NETRESOURCE) );
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = NULL;
nr.lpRemoteName = NULL;
nr.lpProvider = NULL;
CONNECTDLGSTRUCT cds;
ZeroMemory( &cds, sizeof( CONNECTDLGSTRUCT ) );
cds.cbStructure = sizeof( CONNECTDLGSTRUCT );
cds.hwndOwner = hOwner;
cds.lpConnRes = &nr;
cds.dwFlags = CONNDLG_USE_MRU;
DWORD dwRet;
dwRet = DllWNetConnectionDialog(
&cds
);
this->AccessName.SetChar( 0, 0 );
this->ErrorDescription.SetChar( 0, 0 );
if ( dwRet == NO_ERROR ) {
if ( cds.dwDevNum == 0 ) {
return false;
}
this->AccessName.SetChar( 2, 0 );
this->AccessName.SetChar( 1, ':' );
this->AccessName.SetChar( 0, 0x40 + cds.dwDevNum );
return true;
}
switch( dwRet ) {
case 0xFFFFFFFF:
this->ErrorDescription.operator = (
"ダイアログ処理はキャンセルされました"
);
break;
case ERROR_INVALID_PARAMETER:
this->ErrorDescription.operator = (
"パラメータに誤りがあります"
);
break;
case ERROR_BAD_DEV_TYPE:
this->ErrorDescription.operator = (
"ディスクタイプに設定されていません"
);
break;
case ERROR_BUSY:
this->ErrorDescription.operator = (
"ネットワークプロバイダがビジーです"
);
break;
case ERROR_NO_NETWORK:
this->ErrorDescription.operator = (
"ネットワークに接続されていません"
);
break;
case ERROR_NOT_ENOUGH_MEMORY:
this->ErrorDescription.operator = (
"ダイアログボックスを表示するための"
"十分なメモリがありません"
);
break;
case ERROR_EXTENDED_ERROR:
this->ErrorDescription.operator = (
"ネットワーク固有のエラーが発生しました"
);
break;
}
return false;
}
| |
|
|
|
|
// *********************************************************
// ディスク資源ダイアログ接続解除
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWNet::DialogDisConnect( HWND hOwner )
{
if ( this->lib == NULL ) {
return false;
}
LPFUNC_WNetDisconnectDialog DllWNetDisconnectDialog;
DllWNetDisconnectDialog =
(LPFUNC_WNetDisconnectDialog)GetProcAddress(
lib, "WNetDisconnectDialog"
);
if ( DllWNetDisconnectDialog == NULL ) {
return false;
}
DWORD dwRet;
dwRet = DllWNetDisconnectDialog(
hOwner,
RESOURCETYPE_DISK
);
this->ErrorDescription.SetChar( 0, 0 );
if ( dwRet == NO_ERROR ) {
return true;
}
return false;
}
| |
|
|
|
|
// *********************************************************
// ディスク資源接続済み一覧
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWNet::EnumConnected( LboxListview *Lview )
{
if ( !(LboxWNetLoadEnumProc( this->lib )) ) {
return false;
}
DWORD dwRet;
NETRESOURCE nr;
HANDLE hHandle;
ZeroMemory( &nr, sizeof(NETRESOURCE) );
nr.dwUsage = RESOURCEUSAGE_CONTAINER;
dwRet = DllWNetOpenEnum(
RESOURCE_CONNECTED,
RESOURCETYPE_DISK,
0,
&nr,
&hHandle
);
if ( dwRet != NO_ERROR ) {
return false;
}
DWORD dwCount;
DWORD dwSize;
int nCnt;
char *Buff;
Buff = new char[1000];
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
Lview->Initialize();
Lview->AddColumn( LVCFMT_LEFT, 100, "" );
Lview->AddColumn( LVCFMT_LEFT, 100, "ローカル" );
Lview->AddColumn( LVCFMT_LEFT, 100, "リモート" );
Lview->AddColumn( LVCFMT_LEFT, 100, "プロバイダ" );
Lview->AddColumn( LVCFMT_LEFT, 100, "コメント" );
NETRESOURCE *pnr;
nCnt = 1;
while( 1 ) {
Lview->AddRow();
Lview->SetColumnPrintf( 0, "%d", nCnt );
nCnt++;
pnr = (NETRESOURCE *)(Buff);
Lview->SetColumnText( 1, pnr->lpLocalName );
Lview->SetColumnText( 2, pnr->lpRemoteName );
Lview->SetColumnText( 3, pnr->lpProvider );
Lview->SetColumnText( 4, pnr->lpComment );
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
break;
}
}
}
Lview->Fit();
DllWNetCloseEnum( hHandle );
delete [] Buff;
return true;
}
| |
|
|
|
|
// *********************************************************
// ドメイン一覧
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWNet::EnumDomain( LboxListview *Lview )
{
if ( !(LboxWNetLoadEnumProc( this->lib )) ) {
return false;
}
DWORD dwRet;
NETRESOURCE *pnr;
HANDLE hHandle;
dwRet = DllWNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
NULL,
&hHandle
);
if ( dwRet != NO_ERROR ) {
return false;
}
DWORD dwCount;
DWORD dwSize;
int nCnt;
char *Buff;
Buff = new char[1000];
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
while( 1 ) {
pnr = (NETRESOURCE *)(Buff);
if ( lstrcmpi(
pnr->lpRemoteName, "Microsoft Windows Network" ) == 0 ) {
break;
}
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
}
DllWNetCloseEnum( hHandle );
dwRet = DllWNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
pnr,
&hHandle
);
if ( dwRet != NO_ERROR ) {
return false;
}
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
Lview->Initialize();
Lview->AddColumn( LVCFMT_LEFT, 100, "" );
Lview->AddColumn( LVCFMT_LEFT, 100, "ローカル" );
Lview->AddColumn( LVCFMT_LEFT, 100, "リモート" );
Lview->AddColumn( LVCFMT_LEFT, 100, "プロバイダ" );
Lview->AddColumn( LVCFMT_LEFT, 100, "コメント" );
nCnt = 1;
while( 1 ) {
Lview->AddRow();
Lview->SetColumnPrintf( 0, "%d", nCnt );
nCnt++;
pnr = (NETRESOURCE *)(Buff);
Lview->SetColumnText( 1, pnr->lpLocalName );
Lview->SetColumnText( 2, pnr->lpRemoteName );
Lview->SetColumnText( 3, pnr->lpProvider );
Lview->SetColumnText( 4, pnr->lpComment );
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
break;
}
}
}
Lview->Fit();
DllWNetCloseEnum( hHandle );
delete [] Buff;
return true;
}
| |
|
|
|
|
// *********************************************************
// サーバー一覧
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWNet::EnumServer( LboxString *LDomain, LboxListview *Lview )
{
return LboxWNet::EnumServer(
LDomain->szLboxString,
Lview
);
}
BOOL LboxWNet::EnumServer( LPTSTR lpDomain, LboxListview *Lview )
{
if ( !(LboxWNetLoadEnumProc( this->lib )) ) {
return false;
}
DWORD dwRet;
NETRESOURCE *pnr;
HANDLE hHandle;
dwRet = DllWNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
NULL,
&hHandle
);
if ( dwRet != NO_ERROR ) {
return false;
}
DWORD dwCount;
DWORD dwSize;
int nCnt;
char *Buff;
Buff = new char[1000];
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
while( 1 ) {
pnr = (NETRESOURCE *)(Buff);
if ( lstrcmpi(
pnr->lpRemoteName, "Microsoft Windows Network" ) == 0 ) {
break;
}
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
}
DllWNetCloseEnum( hHandle );
dwRet = DllWNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
pnr,
&hHandle
);
if ( dwRet != NO_ERROR ) {
return false;
}
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
while( 1 ) {
pnr = (NETRESOURCE *)(Buff);
if ( lstrcmpi(
pnr->lpRemoteName, lpDomain ) == 0 ) {
break;
}
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
break;
}
}
}
DllWNetCloseEnum( hHandle );
dwRet = DllWNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
pnr,
&hHandle
);
if ( dwRet != NO_ERROR ) {
return false;
}
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
DllWNetCloseEnum( hHandle );
delete [] Buff;
return false;
}
}
Lview->Initialize();
Lview->AddColumn( LVCFMT_LEFT, 100, "" );
Lview->AddColumn( LVCFMT_LEFT, 100, "ローカル" );
Lview->AddColumn( LVCFMT_LEFT, 100, "リモート" );
Lview->AddColumn( LVCFMT_LEFT, 100, "プロバイダ" );
Lview->AddColumn( LVCFMT_LEFT, 100, "コメント" );
nCnt = 1;
while( 1 ) {
Lview->AddRow();
Lview->SetColumnPrintf( 0, "%d", nCnt );
nCnt++;
pnr = (NETRESOURCE *)(Buff);
Lview->SetColumnText( 1, pnr->lpLocalName );
Lview->SetColumnText( 2, pnr->lpRemoteName );
Lview->SetColumnText( 3, pnr->lpProvider );
Lview->SetColumnText( 4, pnr->lpComment );
dwCount = 1;
dwSize = 1000;
dwRet = DllWNetEnumResource(
hHandle,
&dwCount,
Buff,
&dwSize
);
if ( dwRet != NO_ERROR ) {
if ( dwRet != ERROR_MORE_DATA ) {
break;
}
}
}
Lview->Fit();
DllWNetCloseEnum( hHandle );
delete [] Buff;
return true;
}
| |
|
|
|