开发者

Converting C++ builder 6 project to C++ builder 2010

I have a simple project that's written in c++ builder 6. It's about encryption RSA algorithm. Wanted to convert to c++ builder 2010 but it gives errors

e.g. source code of main project

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UTForm.h"
#include "UTRSA.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
randomize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Cli开发者_JAVA百科ck(TObject *Sender)
{
TRSA a(Edit4->Text.ToInt());

char* tmp = a.KeyModul;
Edit1->Text = AnsiString(tmp);
tmp = a.OpenKey;
Edit2->Text = AnsiString(tmp);
tmp = a.SecretKey;
Edit3->Text = AnsiString(tmp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TNumber n(Edit1->Text.c_str());
TNumber e(Edit2->Text.c_str());
TNumber d(Edit3->Text.c_str());

THexString text;
text.AsCharString = Edit5->Text;

if (Edit3->Text != "")
  {
  TRSA a(n,e,d,Edit4->Text.ToInt());
  a.PlainText = text;
  Edit6->Text = a.CryptedText.AsHexString;
  }
else
  {
  TRSA a(n,e,Edit4->Text.ToInt());
  a.PlainText = text;
  Edit6->Text = a.CryptedText.AsHexString;
  }
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
TNumber n(Edit1->Text.c_str());
TNumber e(Edit2->Text.c_str());
TNumber d(Edit3->Text.c_str());

THexString text;
text.AsHexString = Edit6->Text;

if (Edit3->Text != "")
  {
  TRSA a(n,e,d,Edit4->Text.ToInt());
  a.CryptedText = text;
  Edit8->Text = a.PlainText.AsCharString;
  }
else
  {
  TRSA a(n,e,Edit4->Text.ToInt());
  a.CryptedText = text;
  Edit8->Text = a.PlainText.AsCharString;
  }
}
//---------------------------------------------------------------------------

errors are:

Build
  Checking project dependencies...
  Compiling RSA.cbproj (Debug configuration)
  [BCC32 Warning] UTHexString.cpp(92): W8012 Comparing signed and unsigned values
  [BCC32 Warning] UTHexString.cpp(92): W8012 Comparing signed and unsigned values
  [BCC32 Warning] UTForm.cpp(29): W8057 Parameter 'Sender' is never used
  [BCC32 Error] UTForm.cpp(33): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
  [BCC32 Error] UTForm.cpp(34): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
  [BCC32 Error] UTForm.cpp(35): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
  [BCC32 Warning] UTForm.cpp(52): W8057 Parameter 'Sender' is never used
  [BCC32 Error] UTForm.cpp(57): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
  [BCC32 Error] UTForm.cpp(58): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
  [BCC32 Error] UTForm.cpp(59): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
  [BCC32 Warning] UTForm.cpp(76): W8057 Parameter 'Sender' is never used
  Failed
  Elapsed time: 00:00:01.5
Project Import
  Upgrading project "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.bpr"
    Reading "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.bpr"
    Upgraded to "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.cbproj"

I think C++ Builder 2010 has default unicode support that's why or I am wrong ? When I looked at the TNumber constructor it has the following:

//---------------------------------------------------------------------------
#ifndef UTNumberH
#define UTNumberH
//---------------------------------------------------------------------------
#include <assert.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>

class TNumber
{
private:
       TNumber   multdigit(int) const;
       TNumber   mult10(int) const;

       char     *vlstr;                          
       int       vlen;                           
       int       vlsign;                         

public:

                 TNumber(const char* = NULL);    
                 TNumber(int);                   
                 TNumber(const TNumber &);       
                ~TNumber();                      

                 operator int() const;
                 operator long() const;
                 operator double() const;
                 operator char*() const;

  const TNumber& operator=(const TNumber&);

     TNumber operator - () const;
     TNumber operator ++ ();
     TNumber operator ++ (int);
     TNumber operator -- ();
     TNumber operator -- (int);

         TNumber operator += (const TNumber &);
     TNumber operator -= (const TNumber &);
     TNumber operator *= (const TNumber &);
     TNumber operator /= (const TNumber &);
     TNumber operator %= (const TNumber &);

  friend TNumber operator + (const TNumber &, const TNumber &);
  friend TNumber operator - (const TNumber &, const TNumber &);
  friend TNumber operator * (const TNumber &, const TNumber &);
  friend TNumber operator / (const TNumber &, const TNumber &);
  friend TNumber operator % (const TNumber &, const TNumber &);

  friend int     operator == (const TNumber &, const TNumber &);
  friend int     operator != (const TNumber &, const TNumber &);
  friend int     operator < (const TNumber &, const TNumber &);
  friend int     operator <= (const TNumber &, const TNumber &);
  friend int     operator > (const TNumber &, const TNumber &);
  friend int     operator >= (const TNumber &, const TNumber &);

         char*   strrev(char *s) const;
  friend TNumber abs(const TNumber &);
  friend TNumber sqrt(const TNumber &);
  friend TNumber pow(const TNumber &, const TNumber &);
  friend double  div(const TNumber &, const TNumber &);

  friend ostream & operator << (ostream &, const TNumber &);
  friend istream & operator >> (istream &, TNumber &);

  friend TNumber rnd(const TNumber& from, const TNumber& to);
};

const TNumber zero = TNumber("0");
const TNumber one  = TNumber("1");
const TNumber two  = TNumber("2");

TNumber eae(TNumber u, TNumber v);             

#endif

Where am I wrong ?

In addition find the c++ builder 6 project attached !


You are correct. UnicodeString is what most strings are by default in 2010. Since the Text property is most likely one of these, the safest way to make things compile would be to convert back using something like the following:

TNumber n( AnsiString( Edit1->Text ).c_str() );

Update:

Based off comments I'll clarify the answer a bit. The answer is assuming that the code is still only expecting ANSi data. Otherwise, a better solution, as David M. indicated, is to change the underlying TNumber class to handle UnicodeString (i.e. wchar_t).


"Parameter 'Sender' is never used".

  • Project => Options
  • С++ Compiler => Warnings
  • "Enable selected Warnings"
  • "8056 Parameter is newer used" - False.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜