Программирую в Embarcadero C++ Builder 11
Dll компилируется спокойно, а вот при компиляции самой программы возникают ошибки:
[ilink32 Error] Error: Unresolved external 'Encrypt' referenced from D:\TTT\WIN32\DEBUG\PROGRAMMA.OBJ
[ilink32 Error] Error: Unresolved external 'Decrypt' referenced from D:\TTT\WIN32\DEBUG\PROGRAMMA.OBJ
[ilink32 Error] Error: Unable to perform link
Ошибка где-то кроется судя по всему в programma но только в чем именно уже 3 дня понять не могу.
programma.cpp
c++//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "parol.h"
#include "dllL.h"
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <cstring>
#include "programma.h"
#include "about.h"
#include "parolchange.h"
#include <fstream>
#include <string>
#include <System.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
// Объявления функций
using namespace std;
extern "C" __declspec(dllimport) UnicodeString __stdcall Encrypt(const UnicodeString &text, int key);
extern "C" __declspec(dllimport) UnicodeString __stdcall Decrypt(const UnicodeString &encryptedText, int key);
TForm2* Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) {}
//---------------------------------------------------------------------------
void __fastcall TForm2::N1Click(TObject* Sender)
{
Form3->ShowModal();
}
//---------------------------------------------------------------------------
// Открытие незашифрованного файла через кнопку
void __fastcall TForm2::Button3Click(TObject* Sender)
{
UnicodeString text = "";
if (OpenDialog1->Execute()) {
text = OpenDialog1->FileName;
Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
}
}
//---------------------------------------------------------------------------
//Сохранение незашифрованного файла через кнопку
void __fastcall TForm2::Button4Click(TObject* Sender)
{
UnicodeString text = "";
if (text != "")
Memo1->Lines->SaveToFile(text);
else if (SaveDialog1->Execute()) {
text = SaveDialog1->FileName;
Memo1->Lines->SaveToFile(SaveDialog1->FileName);
}
}
//---------------------------------------------------------------------------
// Открытие зашифрованного файла через кнопку
void __fastcall TForm2::Button6Click(TObject* Sender)
{
UnicodeString text = "";
if (OpenDialog1->Execute()) {
text = OpenDialog1->FileName;
Memo2->Lines->LoadFromFile(OpenDialog1->FileName);
}
}
//---------------------------------------------------------------------------
//Сохранение зашифрованного файла через кнопку
void __fastcall TForm2::Button5Click(TObject* Sender)
{
UnicodeString text = "";
if (text != "")
Memo2->Lines->SaveToFile(text);
else if (SaveDialog1->Execute()) {
text = SaveDialog1->FileName;
Memo2->Lines->SaveToFile(SaveDialog1->FileName);
}
}
//---------------------------------------------------------------------------
// Открытие незашифрованного файла через меню
void __fastcall TForm2::N10Click(TObject* Sender)
{
UnicodeString text = "";
if (OpenDialog1->Execute()) {
text = OpenDialog1->FileName;
Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
}
}
//---------------------------------------------------------------------------
// Сохранение незашифрованного файла через меню
void __fastcall TForm2::N11Click(TObject* Sender)
{
UnicodeString text = "";
if (text != "")
Memo1->Lines->SaveToFile(text);
else if (SaveDialog1->Execute()) {
text = SaveDialog1->FileName;
Memo1->Lines->SaveToFile(SaveDialog1->FileName);
}
}
//---------------------------------------------------------------------------
// Открытие зашифрованного файла через меню
void __fastcall TForm2::N12Click(TObject* Sender)
{
UnicodeString text = "";
if (OpenDialog1->Execute()) {
text = OpenDialog1->FileName;
Memo2->Lines->LoadFromFile(OpenDialog1->FileName);
}
}
//---------------------------------------------------------------------------
// Сохранение зашифрованного файла через меню
void __fastcall TForm2::N13Click(TObject* Sender)
{
UnicodeString text = "";
if (text != "")
Memo2->Lines->SaveToFile(text);
else if (SaveDialog1->Execute()) {
text = SaveDialog1->FileName;
Memo2->Lines->SaveToFile(SaveDialog1->FileName);
}
}
//---------------------------------------------------------------------------
// Вызов окна смены пароля
void __fastcall TForm2::N7Click(TObject* Sender)
{
Form4->Show();
}
//---------------------------------------------------------------------------
//Вызов окна О программе
void __fastcall TForm2::N9Click(TObject* Sender)
{
Form3->ShowModal();
}
//---------------------------------------------------------------------------
//Завершение работы программы, закрытие главного окна
void __fastcall TForm2::N5Click(TObject* Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject* Sender)
{
HINSTANCE hDll = LoadLibrary(L"dllL.dll"); // Загрузка DLL-библиотеки
if (hDll)
{
// Получение значения ключа из компонента TEdit
int key = StrToInt(Edit1->Text);
// Шифрование текста из Memo1 и вывод результата в Memo2
UnicodeString encryptedText = Encrypt(Memo1->Text, key);
Memo2->Text = encryptedText;
}
else
{
ShowMessage("Не удалось загрузить библиотеку dllL.dll");
}
FreeLibrary(hDll);
if (Memo1->Lines->Text == "") {
ShowMessage("Введите незашифрованный файл!");
}
if (Edit1->Text == "") {
ShowMessage("Введите ключ!");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button2Click(TObject* Sender)
{ HINSTANCE hDLL = LoadLibrary(L"dllL.dll");
if (hDLL)
{
/// Получение значения ключа из компонента TEdit
int key = StrToInt(Edit1->Text);
// Расшифровка текста из Memo2 и вывод результата в Memo1
UnicodeString decryptedText = Decrypt(Memo2->Text, key);
Memo1->Text = decryptedText;
}
else
{
ShowMessage("Не удалось загрузить библиотеку dllL.dll");
}
FreeLibrary(hDLL);
if (Memo2->Lines->Text == "") {
ShowMessage("Введите незашифрованый файл!");
}
if (Edit1->Text == "") {
ShowMessage("Введите ключ!");
}
//---------------------------------------------------------------------------
}
programma.h
//---------------------------------------------------------------------------
#ifndef programmaH
#define programmaH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Dialogs.hpp>
#include <Vcl.Menus.hpp>
#include <System.hpp>
#include "dllL.h"
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <cstring>
#include "programma.h"
#include "about.h"
#include "parolchange.h"
#include <fstream>
#include <string>
#include <System.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TButton Button1;
TButton Button2;
TButton Button3;
TMemo Memo1;
TOpenDialog OpenDialog1;
TMainMenu MainMenu1;
TMemo Memo2;
TButton Button4;
TButton Button5;
TButton Button6;
TMenuItem N1;
TMenuItem N2;
TMenuItem N3;
TMenuItem N4;
TMenuItem N5;
TMenuItem N6;
TMenuItem N7;
TMenuItem N8;
TMenuItem N9;
TSaveDialog SaveDialog1;
TMenuItem N10;
TMenuItem N11;
TMenuItem N12;
TMenuItem N13;
TLabel Label1;
TLabel Label2;
TLabel Label4;
TEdit Edit1;
void __fastcall N1Click(TObject Sender);
void __fastcall Button3Click(TObject Sender);
void __fastcall Button6Click(TObject Sender);
void __fastcall N10Click(TObject Sender);
void __fastcall N12Click(TObject Sender);
void __fastcall N11Click(TObject Sender);
void __fastcall N13Click(TObject Sender);
void __fastcall N5Click(TObject Sender);
void __fastcall Button5Click(TObject Sender);
void __fastcall Button4Click(TObject Sender);
void __fastcall N7Click(TObject Sender);
void __fastcall N9Click(TObject Sender);
void __fastcall Button1Click(TObject Sender);
void __fastcall Button2Click(TObject Sender);
private:
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
extern "C" __declspec(dllexport) UnicodeString __stdcall Encrypt(const UnicodeString &text, int key);
extern "C" __declspec(dllexport) UnicodeString __stdcall Decrypt(const UnicodeString &encryptedText, int key);
//---------------------------------------------------------------------------
#endif
dllL.cpp
#if defined(__BORLANDC__) && defined(__clang__) && defined(_WIN32) && !defined(_WIN64)
#pragma hdrstop
#pragma argsused
#include <string.h>
#include <string>
#include "dllL.h"
#include <iostream>
#include <fstream>
#include <windows.h>
#include <System.hpp>
using namespace std;
extern "C" __declspec(dllexport) UnicodeString __stdcall Encrypt(const UnicodeString &text, int key);
extern "C" __declspec(dllexport) UnicodeString __stdcall Decrypt(const UnicodeString &encryptedText, int key);
UnicodeString __stdcall Encrypt(const UnicodeString &text, int key) {
UnicodeString result;
for (int i = 1; i <= text.Length(); ++i) {
wchar_t ch = text[i];
wchar_t newChar = ch + (key + i) % 256;
result += newChar;
}
return result;
}
UnicodeString __stdcall Decrypt(const UnicodeString &encryptedText, int key) {
UnicodeString result;
for (int i = 1; i <= encryptedText.Length(); ++i) {
wchar_t ch = encryptedText[i];
wchar_t newChar = ch - (key + i) % 256;
result += newChar;
}
return result;
}
#endif
dllL.h
#ifdef _WIN32
#include <tchar.h>
#endif