vendredi 25 septembre 2020

delphi and android dynamic library

I've compiled a small dynamic Android Arm library (in c ++) just to test how Delphi can interact with it (as a starting point for another real big project) : Here's my c++ :

const char* TestHelloWorld()

    {

    std::string a = "world";
    std::string b = (boost::format("hello: %s") % a).str();    
    char* c = const_cast<char*>(b.c_str());    
    LOGI("%s", c);// using android log ( adb )     
    return c;

    }

and here's my Delphi implementation :

procedure TForm7.Button1Click(Sender: TObject);
var
    DocDir, LibFN: string;
    _TestHelloWorld: function() : MarshaledAString; cdecl;   
    hLib: HMODULE;
    begin
     DocDir := IncludeTrailingPathDelimiter(TPath.GetLibraryPath);
      LibFN:=DocDir + 'libtest-cpp.so';
      hLib := LoadLibrary(PWideChar(LibFN));
      if hLib<>0 then
      begin
       _TestHelloWorld: GetProcAddress(hLib, 'TestHelloWorld');  
        ShowMessage(_TestHelloWorld: );     
      end;
    end;

The result in the Android Log :

enter image description here

The result with delphi :

enter image description here

So please what's the issue with my delphi code ; is related to using MarshaledAString ?

PS : I'm using RAD Studio Tokyo version .

Aucun commentaire:

Enregistrer un commentaire