我在尝试返回一个对象时遇到了一些麻烦(我在返回课时也面临问题,但这不是问题的焦点,我只是解释因为你可能会看到评论错误在代码中。)
代码的目的是返回一个TMemo以使其与现有对象相等,如下所示:
Memo1 = CriptLibDll::CriptLib::Encriptar(anyString, anyString, Memo1)
以下是文件:
CriptLib.h:
#ifndef CriptLibDllH
#define CriptLibDllH
#ifdef CRIPTNSDLL_EXPORTS
#define CRIPTLIBDLL_API __declspec(dllexport)
#else
#define CRIPTLIBDLL_API __declspec(dllimport)
#endif
#ifdef __cplusplus
#include <fmx.h>
#include <System.Classes.hpp>
#include <string.h>
#include <FMX.Memo.hpp>
extern "C" {
#endif
CRIPTLIBDLL_API TMemo* Cript_BasicoM(String Original, String Chave, TMemo* Memo);
// CRIPTLIBDLL_API TStringList Cript_BasicoL(String Original, String Chave, TSringList Lista);
CRIPTLIBDLL_API String Cript_BasicoS(String Original, String Chave, String Linha);
#ifdef __cplusplus
}
namespace CriptLib
{
class Encriptar
{
public:
TMemo* Subst(String Original, String Chave, TMemo* Memo) { return Cript_BasicoM(Original, Chave, Memo); }
// static TStringList Subst(String Original, String Chave, TSringList Lista) { return Cript_BasicoL(Original, Chave, Lista); }
String Subst(String Original, String Chave, String Linha) { return Cript_BasicoS(Original, Chave, Linha); }
};
}
#endif
#endif
CriptLib.cpp:
#define CRIPTNSDLL_EXPORTS
#include "CriptLib.h"
#include <fmx.h>
#include <FMX.Memo.hpp>
#include <System.Classes.hpp>
#include <string.h>
//---------------------------------------------------------------------------
TMemo* Cript_BasicoM(String Original, String Chave, TMemo* Memo){
TMemo* Encriptado = Memo;
if (Original.Length() != Chave.Length()) {
throw Exception (L"O tamanho das palaras chave e original não podem ser diferentes");
}
String Linha = NULL;
for (int i = 0; i < Original.Length(); i++) {
for (int k = 0; k < Encriptado->Lines->Count; k++) {
Linha = Encriptado->Lines->Strings[k];
for (int l = 0; l < Linha.Length(); l++) {
if (Linha[l] == Original[i]) Linha[l] = Chave [i];
}
Encriptado->Lines->Strings[k] = Linha;
}
}
Encriptado->Lines->Add(Original);
Encriptado->Lines->Add("CriptB");
return Encriptado;
}
//---------------------------------------------------------------------------
/*TStringList Cript_BasicoL (String Original, String Chave, TStringList Lista){
TStringList* Encriptado = new TStringList;
Encriptado->Strings = Lista->Strings;
if (Original.Length() != Chave.Length()) {
throw Exception (L"O tamanho das palaras chave e original não podem ser diferentes");
}
String Linha = NULL;
for (int i = 0; i < Original.Length(); i++) {
for (int k = 0; k < Encriptado->Count; k++) {
Linha = Encriptado->Strings[k];
for (int l = 0; l < Linha.Length(); l++) {
if (Linha[l] == Original[i]) Linha[l] = Chave [i];
}
Encriptado->Strings[k] = Linha;
}
}
Encriptado->Add(Original);
Encriptado->Add("CriptB");
return Encriptado;
} */
//---------------------------------------------------------------------------
String Cript_BasicoS (String Original, String Chave, String Linha){
String Encriptado = Linha;
if (Original.Length() != Chave.Length()) {
throw Exception (L"O tamanho das palaras chave e original não podem ser diferentes");
}
for (int i = 0; i < Original.Length(); i++) {
for (int l = 0; l < Encriptado.Length(); l++) {
if (Encriptado[l] == Original[i]) Encriptado[l] = Chave [i];
}
}
return Encriptado;
}
//---------------------------------------------------------------------------
错误我现在已经到了:
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \ LIB \引用的未解析的外部'__fastcall System :: Internal :: Strhlpr :: UnicodeFree(System :: UnicodeString&amp;)' WIN32 \ DEBUG \ VCLE.LIB | ustring
[ilink32错误]错误:未解析的外部'__fastcall System :: Syncobjs :: TInterlocked :: Increment(int&amp;)'从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \ LIB \ WIN32 \ DEBUG引用\ VCLE.LIB | ustring
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \引用的未解析的外部'__fastcall System :: Internal :: Strhlpr :: UnicodeAssign(System :: UnicodeString&amp;,System :: UnicodeString&amp;)' STUDIO \ 15.0 \ LIB \ WIN32 \ DEBUG \ VCLE.LIB | ustring
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \引用的未解析的外部'__fastcall System :: Internal :: Strhlpr :: UnicodeSetLength(System :: UnicodeString&amp;,int)' LIB \ WIN32 \ DEBUG \ VCLE.LIB | ustring
[ilink32错误]错误:未解析的外部'System :: Sysutils :: Exception ::'从C:\ USERS \ USER \ DOCUMENTS \ DESENVOLVIMENTO BASE \ TT2 \ WIN32 \ DEBUG \ CRIPTLIB.OBJ引用
[ilink32错误]错误:从C:\ USERS \ USER \ DOCUMENTS \ DESENVOLVIMENTO BASE \ TT2 \ WIN32 \ DEBUG \引用的未解析的外部'__fastcall System :: Sysutils :: Exception :: Exception(System :: UnicodeString)' CRIPTLIB.OBJ
[ilink32错误]错误:从C:\ USERS \ USER \ DOCUMENTS \ DESENVOLVIMENTO BASE \ TT2 \ WIN32 \ DEBUG \ CRIPTLIB.OBJ引用的未解析的外部'__fastcall System :: Sysutils :: Exception :: ~Exception()'
[ilink32错误]错误:从C:\ USERS \ USER \ DOCUMENTS \ DESENVOLVIMENTO BASE \ TT2 \ WIN32 \ DEBUG \ CRIPTLIB.OBJ
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \ LIB \ WIN32 \ DEBUG \ VCLE.LIB | ustring
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \ LIB \ WIN32 \ DEBUG \ VCLE引用的未解析的外部'__fastcall System :: LoadResString(System :: TResStringRec *)'。 LIB | syssupp
[ilink32错误]错误:未解析的外部'System :: Sysutils :: ERangeError ::'从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \ LIB \ WIN32 \ DEBUG \ VCLE.LIB | ustring引用
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO \ 15.0 \ LIB \ WIN32 \ DEBUG \ VCLE引用的未解析的外部'__fastcall System :: UniqueString(System :: UnicodeString&amp;)'。 LIB | ustring
[ilink32错误]错误:从C:\ PROGRAM FILES(X86)\ EMBARCADERO \ STUDIO引用的未解析的外部'__fastcall System :: Internal :: Strhlpr :: UnicodeFromPChar(System :: UnicodeString&amp;,char *,bool)' \ 15.0 \ LIB \ WIN32 \ DEBUG \ VCLE.LIB | ustring
[ilink32错误]错误:无法执行链接
用于(尝试)构建此项目的引用:
How to “return an object” in C++?
C++ return a class object by reference
Fill a TStringList in a DLL(不幸的是德尔福)
从现在开始,非常感谢