Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello. I have such function. But there is an error: "R6010 - abort has been called". Could anyone help me with this error?
C++
void Encrypt (char *pszFile, char *pszSecret) {
	int size;
	char *buf;
	_bstr_t cipherText;
	string name;
	ifstream in (pszFile, ios::in | ios::binary | ios::ate);
	ofstream out;
	IAlgorithmPtr algo;
	IEncryptedDataPtr encryptor;

	if ( !in.is_open() )
		cout << szErrNoFile << std::endl;

	else {
		size = in.tellg();

		buf = new char[size + 1];
		buf[size] = 0;

		in.seekg(0, ios::beg);
		in.read(buf, size);
		in.close();
  
		encryptor.CreateInstance("CAPICOM.EncryptedData");
		encryptor->PutContent(_bstr_t (buf)); //I THINK ERROR IS HERE

		algo = encryptor->GetAlgorithm();
		algo->PutName(CAPICOM_ENCRYPTION_ALGORITHM_AES);
		algo->PutKeyLength(CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM);

		encryptor->SetSecret(_bstr_t (pszSecret), CAPICOM_SECRET_PASSWORD);

		cipherText = encryptor->Encrypt(CAPICOM_ENCODE_BASE64);

		name = pszFile;
		name.append(".encrypted");
		out.open(name.c_str(), ios::out | ios::binary);


		if ( !out.is_open() )
			cout << szErrWrite << endl;

		else {
			out << cipherText;
			out.close();
		}
	}
}
Posted
Comments
Jibesh 1-Feb-13 13:55pm    
are you sure you have downloaded the Platform SDK with this 'Capicom.dll' and registered in your PC?

Read this article

1 solution

That's an unusual error. R6010 is an abort from the C library, MSVCRT in this case. I'd check that your program really gets as far as the line you've indicated. (by setting a breakpoint) If so then you must be doing some serious memory corruption. If not than my guess would be you've got the wrong libraries linked up and your program is failing on startup. Don't usually see an R6010 except during startup. Have you doctored the /ENTRYPOINT or something?
Anyway if it is getting to the point you've marked make sure encryptor is initialised correctly so you can assign to it and don't use BSTRs unless you absolutely have to, they're not know as BeeStings for nothing. You could also try a larger buffer in case encryption is increasing the length of your data.
By the time you've tried all that you'll probably have spotted some mistake that I missed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900