CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    111

    Convert Arduino library to visual c++ dll

    Hey all I am trying my best to fixed these few errors below. The C++ code is from an Arduino library that i wanted to convert to Visual C++ dll for use in one of my C# applications.

    These are the areas that have the errors:

    Code:
    void AES::do_aes_encrypt(BYTE *plain,int size_p,BYTE *cipher,BYTE *key, int bits, BYTE ivl [N_BLOCK]){
      calc_size_n_pad(size_p);
      BYTE plain_p[get_size()];
      padPlaintext(plain,plain_p);
      int blocks = get_size() / N_BLOCK;
      set_key(key, bits) ;
      cbc_encrypt(plain_p, cipher, blocks, ivl);
    }
    The "BYTE plain_p[get_size()];" has the error of "'this' cannot be used in a constant expression".

    Code:
    string AES::letsDecrypt(BYTE *key, string msg, AES aes) {
      char data_decoded[200];
      char iv_decoded[200];
      char temp[200];
      BYTE out[200];
       
      aes.set_key(key, sizeof(key));
      msg.toCharArray(temp, 200);
      int b64len = base64_decode(data_decoded, temp, msg.length());
      string(iv_Encoded).toCharArray(temp, 200);
      
      base64_decode(iv_decoded, temp, string(iv_Encoded).length());  
      aes.do_aes_decrypt((BYTE *)data_decoded, b64len, out, key, 128, (BYTE *)iv_decoded);
      char message[msg.length()];
      char* msgBase64 = (char *)out;
        
      base64_decode(message, (char *)out, msg.length());
    
      return std::string(message);
    }
    The "msg.toCharArray(temp, 200);" has the error of "class "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" has no member "toCharArray"".

    Another error on the same code above "char message[msg.length()];" has the error of "expression must have a constant value".

    And lastly i get this error: "unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?" Which when i try to include it-it says it cant be found.

    Help would be great!

  2. #2
    Join Date
    Nov 2018
    Posts
    120

    Re: Convert Arduino library to visual c++ dll

    > The C++ code is from an Arduino library that i wanted to convert to Visual C++ dll for use in one of my C# applications.
    Why?

    There's already AES built into C# by Microsoft themselves.
    https://docs.microsoft.com/en-us/dot...ramework-4.7.2

    Even if you didn't like that, there are plenty of C++ implementations which use more vanilla C++, than having to cope with the idiosyncrasies that Arduino adds to the mix.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Convert Arduino library to visual c++ dll

    Code:
    BYTE plain_p[get_size()];
    In c++ the size of an array must be known at compile time. It can't be set at run-time as is tried here. If you need to determine the size at run-time then you should use a vector. See http://www.cplusplus.com/reference/vector/vector/
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured