Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Text convertor help

    SDK Help
    0
    4
    310
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 30/06/2004 at 16:12, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   8.5 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      I am trying to write a text converting routine that would take Cinema 4D string and convert them to standard C++ strings (chars).

      I have gotten some code from this forum that works well as long as I put it in the main execute section of the plugin. When I try to make a function/class/whatever its called out of it, it fails. Here is the code:

      char ConvertString (String origString)
      {
           LONG len = origString.GetCStringLen();
           CHAR* sqlStr = bNew CHAR[len+1];
           return origString.GetCString(sqlStr,len+1);
      }

      I call the function like
      exportfile << ConvertString(object->GetName()) < "\n". When I use this to write out to a text file, it doesn't work. If I take the exact same code and place it right before Im going to write out the text file, it works, for example:

      LONG len = object->GetName().GetCStringLen();
      CHAR* sqlStr = bNew CHAR[len+1];
      object->GetName().GetCString(sqlStr, len+1);
      exportfile << sqlStr < "\n";

      Can anyone help a newbie?
      Matt

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 30/06/2004 at 21:13, xxxxxxxx wrote:

        GetCString() returns the length of the string, not the pointer to it. So your function should return sqlStr instead, and the type should be char*, not char. Note that you also have a memory leak to fix, since the string array is never freed. Perhaps you would find it easier to use std::string? (See the conversion functions in https://developers.maxon.net/forum/topic/1700.)

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 01/07/2004 at 08:47, xxxxxxxx wrote:

          I tried the std::String functions and couldn't get them to work correctly with the ofstream and << operator. I also know about the memory leak, but I didn't know how to fix it since I can't delete the sqlStr variable because I need to return it. How could I go about pluggin the leak in the function above?

          By the way, if I return the sqlStr as you suggested, everything works fine. Thank you. Now if I can just plug the leak I will be in business.

          Matt

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 04/07/2004 at 21:37, xxxxxxxx wrote:

            That's weird, because std::string (note lowercase s) should be best friend with std::ofstream etc. Could you show an example?
            If your function cannot handle all of its memory itself, which it can't by your design, then you need to document this and make sure all users of the function free the memory for you.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post