Linker error 2001, unresolved externals

VS2010, Win32 Console Project, i want to use MsiGetFileSignatureInformation from a CLI exe to get the cert data from a .cer public key to a file (which is needed by Windows Installer msi database files)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// mycert.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	DWORD dwWritten;
	DWORD bigEnough;
		
	HANDLE hCertFile;
	BYTE *pbHashData = new BYTE[bigEnough];  // call api to find out real size first in real code
	DWORD pbHashDatasize = bigEnough;
	PCCERT_CONTEXT certcontext = NULL;

	// Get the cert data
	MsiGetFileSignatureInformation(argv[1], 0, &certcontext, pbHashData, &pbHashDatasize);
		
	// Write it to a file
	hCertFile = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
	WriteFile(hCertFile, certcontext->pbCertEncoded, certcontext->cbCertEncoded, &dwWritten, NULL);
	CloseHandle(hCertFile);

	// Clean up
	CertFreeCertificateContext(certcontext);
	
	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include <Windows.h>
#include <Msi.h>
#include <WinCrypt.h>

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>



// TODO: reference additional headers your program requires here 


results in
1
2
3
4
5
6
7
8
1
1>  stdafx.cpp
1>  mycert.cpp
1>c:\users\ferdi\documents\visual studio 2010\projects\mycert\mycert.cpp(12): warning C4700: uninitialized local variable 'bigEnough' used
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
1>mycert.obj : error LNK2001: unresolved external symbol __imp__CertFreeCertificateContext@4
1>mycert.obj : error LNK2001: unresolved external symbol _MsiGetFileSignatureInformationW@20
1>C:\Users\ferdi\Documents\Visual Studio 2010\Projects\mycert\Debug\mycert.exe : fatal error LNK1120: 2 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

You need to link to crypt32.lib and msi.lib

See the bottom of these pages under Requirements

http://msdn.microsoft.com/en-us/library/aa370121(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa376075(VS.85).aspx
And pay attention to that warning.
Topic archived. No new replies allowed.