[Linker Error] Error: Unresolved external '...' referenced from ...


2006-04-18 10:17:48 PM
cppbuilder74
Every once in a while I get linker errors that just don't seem to make
sense! :-(
This particular example is very simple and works no problem with Visual
Studio but not in C++ Builder 2006. The included ibs_common_crypto.h
file and it's source file are pasted at the end of this message.
I've tried starting the project from scratch, deleting object files,
anything I can think of but nothing works.
Any help with this one is very much appreceated. Thanks ...
Here's the scenario.
The following code ...:
=========
#include <string>
#include "ibs_common_crypto.h" // code for this pasted later in this
message
std::string s = "this is my secret data";
std::string ccs = ibs_crypt(s, 'e');
produces the error ...:
====
[Linker Error] Error: Unresolved external 'CryptProtectData' referenced
from D:\_SRC\IBS\SBR\QBSBR\RELEASE_BUILD\IBS_COMMON_CRYPTO.OBJ
source file:
ibs_common_crypto.h
================
#ifndef ibs_common_cryptoH
#define ibs_common_cryptoH
#include <string>
//---------------------------------------------------------------------------
std::string ibs_crypt(const std::string&, char);
#endif
ibs_common_crypto.cpp
==================
#pragma hdrstop
#include "ibs_common_crypto.h"
#include <string>
#include <vector>
#include "windows.h"
#include "wincrypt.h"
std::string ibs_crypt(const std::string& secretData, char eord) {
std::string::const_iterator i = secretData.begin();
std::string::size_type s = secretData.size();
BYTE* puc = new BYTE[s + 1];
BYTE* puc1 = puc;
while (i != secretData.end()) {
*puc = (BYTE)(*i);
++i;
++puc;
}
DATA_BLOB blobIn;
blobIn.pbData = puc1;
blobIn.cbData = s;
// Optional entropy via an external function call
DATA_BLOB blobEntropy;
blobEntropy.pbData = reinterpret_cast<BYTE *>("whatever");
blobEntropy.cbData = lstrlen(
reinterpret_cast<char *>(blobEntropy.pbData));
DATA_BLOB blobOut;
BYTE* pb;
if (eord == 'e') {
if(!CryptProtectData(
&blobIn,
NULL,
&blobEntropy,
NULL,
NULL,
0,
&blobOut)) {
// error
}
} else if (eord == 'd') {
if(!CryptUnprotectData(
&blobIn,
NULL,
&blobEntropy,
NULL,
NULL,
0,
&blobOut)) {
// error
}
}
// convert encrypted / decrypted blob to std::string
std::vector<char>crpC;
pb = blobOut.pbData;
for(DWORD dw = 0; dw != blobOut.cbData; dw++) {
crpC.push_back((char)(*pb));
pb++;
}
std::string crpt;
crpt = std::string(crpC.begin(), crpC.end());
delete [] puc1;
LocalFree(blobOut.pbData);
return crpt;
}
#pragma package(smart_init)