LboxWNet


  Connect



  
// *********************************************************
// ディスク資源接続
// 戻り値 : 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;

}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ