win2000,vc6.0控制台做了一个获取本机网卡的小程序。遇到困难,请求帮助。我是新手我没分了,可怜,多谢了!源码:#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;ASTAT Adapter;void main (void)
{
NCB ncb;
UCHAR uRetCode;
char NetName[50]; memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0; uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode ); memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0; strcpy( ncb.ncb_callname, "* " );
ncb.ncb_buffer = (char *)&Adapter;
ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}错误信息:
--------------------Configuration: getmac - Win32 Debug--------------------
Compiling...
getmac.cpp
D:\vc\getmac\getmac.cpp(33) : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [16]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\vc\getmac\getmac.cpp(34) : error C2440: '=' : cannot convert from 'char *' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...getmac.exe - 2 error(s), 0 warning(s)
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;ASTAT Adapter;void main (void)
{
NCB ncb;
UCHAR uRetCode;
char NetName[50]; memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0; uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode ); memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0; strcpy( ncb.ncb_callname, "* " );
ncb.ncb_buffer = (char *)&Adapter;
ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}错误信息:
--------------------Configuration: getmac - Win32 Debug--------------------
Compiling...
getmac.cpp
D:\vc\getmac\getmac.cpp(33) : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [16]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\vc\getmac\getmac.cpp(34) : error C2440: '=' : cannot convert from 'char *' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...getmac.exe - 2 error(s), 0 warning(s)
解决方案 »
- VC 网络程序无法接收数据
- 在使用 StartDocPrinter,WritePrinter 打印时,汉字是乱码,哪位高手帮忙解决以下?
- 请教如何判断一个分区是真正的物理驱动器上的分区
- 动态数组读写
- 如何将CString转换为DWORD类型?
- 请教基础问题如何向指定ip指定端口发送指定好了的数据包
- 四级没过没有学位,找工作中很重要吗?找人替考好,还是空手啊?望大家给个意见,替考还是决定不了
- 如何将一个二进制数组赋值给一个VARIANT?
- sdl进行视频显示的时候 初始化话成功之后 会出现一个黑色的显示区域,如何让显示区域透明显示呢,就是不出现这个黑色的背景呢?
- 关于Combox的使用疑问!?
- 高分求教:一个很专业的问题,小弟谢谢了。
- 为什么绑定总是出错呢?
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>#include <Nb30.h>//要加这个头文件typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;ASTAT Adapter;void main()
{
NCB ncb;
UCHAR uRetCode;
char NetName[50]; memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0; uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode ); memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0;//改成酱子--〉
memset( &ncb.ncb_callname, 0, sizeof(NCBNAMSZ) );//
ncb.ncb_callname[0]='*';//
ncb.ncb_buffer = (unsigned char *)&Adapter;//
//<--
ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}
最后被忘了还要链一个库文件:netapi32.lib
换一下参数类型,
如果不行的话就用sprintf吧。我是这样用的:strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName);
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#pragma comment(lib,"netapi32.lib")
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;ASTAT Adapter;void main (void)
{
NCB ncb;
UCHAR uRetCode;
char NetName[50]; memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0; uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode ); memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0; strcpy((char*) ncb.ncb_callname, "*" );
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}这样就ok了
删除后就可以了。调试环境:win2000p+vc++6.0