// com.cpp : Implementation of DLL Exports.
// Note: Proxy/Stub Information
//      To build a separate proxy/stub DLL, 
//      run nmake -f comps.mk in the project directory.#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "com.h"#include "com_i.c"//#include < mfc.h >
#include < windows.h >
#include < wincon.h >
#include < stdlib.h >
#include < stdio.h >
#include < time.h >
#include < nb30.h > 
#include <conio.h> // 因为是通过NetAPI来获取网卡信息,所以需要包含其题头文件nb30.h 
typedef struct _ASTAT_
{
    ADAPTER_STATUS adapt;
    NAME_BUFFER    NameBuff [30];
}ASTAT, * PASTAT;ASTAT Adapter;  // 定义一个存放返回网卡信息的变量 
 // 输入参数:lana_num为网卡编号,一般地,从0开始,但在Windows 2000中并不一定是连续分配的 
CComModule _Module;BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()/////////////////////////////////////////////////////////////////////////////
// DLL Entry Pointextern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        _Module.Init(ObjectMap, hInstance, &LIBID_COMLib);
        DisableThreadLibraryCalls(hInstance);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
        _Module.Term();
    return TRUE;    // ok
}/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLESTDAPI DllCanUnloadNow(void)
{
    return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested typeSTDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
    return _Module.GetClassObject(rclsid, riid, ppv);
}/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registrySTDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    return _Module.RegisterServer(TRUE);
}/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registrySTDAPI DllUnregisterServer(void)
{
    return _Module.UnregisterServer(TRUE);
}
void getmac_one (int lana_num,UCHAR lana_val[6])
{
    NCB ncb;
    UCHAR uRetCode;
// CString s;    memset( &ncb, 0, sizeof(ncb) );
    ncb.ncb_command = NCBRESET;
    ncb.ncb_lana_num = lana_num;   
// 指定网卡号 // 首先对选定的网卡发送一个NCBRESET命令,以便进行初始化 
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 = lana_num;  // 指定网卡号    strcpy( (char *)ncb.ncb_callname, 
"*               " );
    ncb.ncb_buffer = (unsigned char *) &Adapter; // 指定返回的信息存放的变量 
ncb.ncb_length = sizeof(Adapter); // 接着,可以发送NCBASTAT命令以获取网卡的信息 
uRetCode = Netbios( &ncb );
//  printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
    if ( uRetCode == 0 )
    { /* 把网卡MAC地址格式化成常用的16进制形式,如0010-A4E4-5802 
s.Format( "The Ethernet Number[%d] is: %02X%02X-%02X%02X-%02X%02X\n",  lana_num,
  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] );
AfxMessageBox(s);
*/for (int i=0;i<6;i++)
lana_val[i]=Adapter.adapt.adapter_address[i];
    }
}int __stdcall mainshow(UCHAR card[6])
{
    NCB ncb;
// CString s;
// char scard[6];    UCHAR uRetCode;
LANA_ENUM lana_enum;    memset( &ncb, 0, sizeof(ncb) );
    ncb.ncb_command = NCBENUM;    ncb.ncb_buffer = (unsigned char *) &lana_enum;
    ncb.ncb_length = sizeof(lana_enum); // 向网卡发送NCBENUM命令,以获取当前机器的网卡信息,如有多少个网卡、每张网卡的编号等 
uRetCode = Netbios( &ncb );
//printf( "The NCBENUM return code is: 0x%x \n", uRetCode );
 if ( uRetCode == 0 )
 {
//printf( "Ethernet Count is : %d\n\n", lana_enum.length); // 对每一张网卡,以其网卡编号为输入编号,获取其MAC地址 
for ( int i=0; i< lana_enum.length; ++i)
getmac_one( lana_enum.lana[i],card); }
getche(); return 0;
}报错信息如下:
--------------------Configuration: com - Win32 Debug--------------------
Linking...
   Creating library Debug/com.lib and object Debug/com.exp
com.obj : error LNK2001: unresolved external symbol _Netbios@4
Debug/com.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.com.dll - 2 error(s), 0 warning(s)
帮忙解决以下,感激不尽!

解决方案 »

  1.   

    在设置中的link选项中的object/library modules 加入Netapi32.lib
    编译
      

  2.   

    在设置中的link选项中的object/library modules 加入Netapi32.lib
      

  3.   

    这个问题是再编译的时候没有导入Netapi32.lib 文件 这样就找不到函数的入口 需要设置 按上面的方法
      

  4.   

    道理非常简单,编译器发现了代码引用的函数声明,但是无法找到函数体。就是不知道怎么执行它。一般是没有包含库文件,首先找找你的代码,看看比较特别的API,在MSDN搜索此API的帮助,看看下面有没有说明,说此API需要哪些库文件,Microsoft的帮助很好,都会有描述的。
        VC里面的Project菜单->Settings
        选个需要加入库的工程,比如DEBUG版本,再选右面的LINK选项卡,把库文件的名字加入此选项:Object/library modules
        OK,可以了。