Avatar of mi1
mi1

asked on 

Question for nietod

I can't to compile my code.
it is an error://
Del_MFC_APIView.obj : error LNK2001: unresolved external symbol __imp__RpcStringFreeA@4
Del_MFC_APIView.obj : error LNK2001: unresolved external symbol __imp__UuidToStringA@8
Del_MFC_APIView.obj : error LNK2001: unresolved external symbol __imp__UuidCreate@4
Debug/Del_MFC_API.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
Creating browse info file...

Del_MFC_API.exe - 4 error(s), 0 warning(s)//
why this happend


#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

BOOL GetNicAddress(LPSTR pszNicAddress, UINT nBufSize);
 
int main(int argc, char* argv[])
{
      UINT buffer=0;
      BOOL success=GetNicAddress("eitan",buffer);
      return 0;
}

BOOL GetNicAddress(LPSTR pszNicAddress, UINT nBufSize)
{
  BOOL bSuccess = FALSE;

  //NIC address is 12 character string
  if (nBufSize < 13)
    return FALSE;

  //the way we determine the NIC address is to call the RPC DCE function
  //UuidCreate. The standard format of the GUID returned contains
  //the NIC address in the last 12 characters. The added advantage to
  //this method is that we do not need to rely on a specific network
  //protocol needing to be installed on the client machine to determine
  //the NIC address. You could use this function as the basis for a
  //security scheme for a networked product of yours. Using the NIC address
  //is a guranteed way of uniquely identify a machine throughout the network.

      UUID Uuid;
      RPC_STATUS rpcStatus = UuidCreate(&Uuid);

  if (rpcStatus == RPC_S_OK)
  {
    unsigned char* pszGuid;
    rpcStatus = UuidToString(&Uuid, &pszGuid);
    if (rpcStatus == RPC_S_OK)
    {
      char* pLastMinus = strrchr((char*)pszGuid, '-');
      if (pLastMinus)
      {
        strcpy(pszNicAddress, pLastMinus+1);
        bSuccess = TRUE;
      }

      //need to free created buffer
      RpcStringFree(&pszGuid);
    }
    else
      printf("Error calling UuidToString, Error value is %d\n", rpcStatus);
  }
  else
  printf("Error calling UuidCreate, Error value is %d\n", rpcStatus);

  return bSuccess;
}
C++

Avatar of undefined
Last Comment
mi1
Avatar of proskig
proskig

You have to link with Rpcrt4.lib
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mi1
mi1

ASKER

Answer accepted
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo