⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit2.cpp

📁 c++builder动态连接paradox数据库的例子程序,在bcb6下编译通过
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
#include "Unit1.h"

#include "get_netinfo.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 Mythread::UpdateCaption()
//     {
 //      Form1->Caption = "Updated in a thread";
 //    }
//---------------------------------------------------------------------------

__fastcall Mythread::Mythread(bool CreateSuspended)
        : TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall Mythread::Execute()
{
        //---- Place thread code here ----
        char mac[20];
        char ip[]="192.168.1.1";
        getmac(mac,ip);
        Form1->Label1->Caption = mac;

}
//---------------------------------------------------------------------------


/*char * Mythread::getmac(char * dest_mac, char * input_ip)
{
     WSADATA wsaData;
     int numberOfHost = 1;
     dest_mac[0]=0;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData); 
if ( iRet != 0 ) 
{ 
//printf( "WSAStartup Error:%d\n", GetLastError() );
strcpy(dest_mac,"init_error");
exit( 0 ); 
} 
int nRemoteAddr = inet_addr( input_ip );
struct hostent* remoteHostent;
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa; 
for ( int i = 0; i < numberOfHost; i ++ )
{ 
//获取远程机器名 
sa.s_addr = nRemoteAddr; 
//printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );
//remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
//if ( remoteHostent )
//printf( "HostName : %s\n",remoteHostent->h_name );
//Form1->Label1->Caption = remoteHostent->h_name ;
//else
//printf( "gethostbyaddr Error:%d\n",GetLastError() );
//发送ARP查询包获得远程MAC地址
//Form1->Label1->Caption = GetLastError();

unsigned char macAddress[6]; 
ULONG macAddLen = 6; 
iRet=SendARP(nRemoteAddr, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen); 
char tmp[3];
if ( iRet == NO_ERROR )
{ 
char *p;
p = dest_mac;
for( int i =0; i<6; i++ )
{
if(macAddress[i]<10)strcat(dest_mac,"0");
sprintf(tmp, "%2x", macAddress[i] );
strncat(dest_mac,tmp,2);
p += sprintf(p, i ? "%02X:" : "%02X:", macAddress[i]);
} 

} 
else 
//printf( "SendARP Error:%d\n", GetLastError());
strcpy(dest_mac,"null");
nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 ); 
}
dest_mac[17]= 0;
return dest_mac;

} */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -