Communication error 2019 - C ++

I wrote the following piece of code in VS2010:

#pragma once
#include "stdafx.h"
#ifndef SECURITY_WIN32
#define SECURITY_WIN32
#endif
#include "windows.h"
#include "sspi.h"

int main( void )
{
    ULONG cPackages = 0;
    PSecPkgInfo pInfo = NULL;
    SECURITY_STATUS stat = EnumerateSecurityPackages(&cPackages, &pInfo);
    if (stat == SEC_E_OK) 
    { 
        for (ULONG i = 0; i < cPackages; i++) 
        { 
            wprintf(L"%s\t%s\n",pInfo[i].Name, pInfo[i].Comment); 
        } 
        FreeContextBuffer(pInfo); 
    } 
    return 0; 

}

      

but during compilation I got the following errors:

error LNK2019: unresolved external symbol _imp_EnumerateSecurityPackagesW @ 8 referenced by function _main

and

error LNK2019: unresolved external symbol _FreeContextBuffer @ 4 reference in function _main

Can anyone help me?

+3


source to share


3 answers


You need to associate with Secur32.lib

.



Go to Project Properties -> Linker -> Input

and add Secur32.lib

to the list.

+5


source


Linking "unresolved external symbol" errors generally means that the required library (s) were not available to resolve the symbol. In the case of VC ++, you get an unadorned character FreeContextBuffer

(which will be missed by the feature), go to http://msdn.microsoft.com and search for that feature. In this case, it will produce "FreeContextBuffer" as the first result. Then you look for the last section "Requirements" and find out what headers the compiler and libraries (your case) need for linker-Secur32.lib. Then add this library in properties of IDE -> Linker -> Input. Or with a directive #pragma comment()

in your code. Hope this helps.



+2


source


#include "stdafx.h"

      

was meant to enable "system" interfaces, it is likely that windows.h is already enabled. So try moving the #define inside stdafx.h before including everything else.

0


source







All Articles