Results 1 to 4 of 4

Thread: Simba's AnsiString to std:string ?

  1. #1
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default Simba's AnsiString to std:string ?

    I am working on plugin containing functions with string as parameter, such as:
    Simba Code:
    procedure stringTest ( str :string );

    I've made this piece of code to convert Simba's string to regular std::string

    Code:
    typedef char* SimbaString ;
    
    extern "C" void __declspec(dllexport) strTest( SimbaString str){
        using namespace std;
        cout << str << endl;
        int *pLen = reinterpret_cast<int*>(str)-1;
        cout << pLen << endl;
        int Len = *pLen;
        cout << Len << endl;
        if (Len > 0) {
        string s = string(str,Len);
    
        } else {
            cout<<"0 length"<<endl;
        }
    }
    and it works until I pass an empty string. Then it gives an access violation, even on first "cout" line.
    Simba Code:
    emptyString := '';

    I have no idea how to fix that. Please help.

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Check if str is null?

  3. #3
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by tls View Post
    Check if str is null?
    I've done it before and still got an access violation so deleted that line, now I've tried again and it works, lol. Thanks.

  4. #4
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Strings are null-terminated, so you should be able to just pass the string to std:string without explicit length.
    Hup Holland Hup!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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