THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/02/2004 at 03:47, xxxxxxxx wrote:
Cinema 4D Version: 8.100
Platform: Windows ;
Language(s) : C++ ;
Can anyone tell me how to convert from String type (SDK) to c string type or the reverse side?
Thanks in advance
On 19/02/2004 at 19:03, xxxxxxxx wrote:
Do you mean the C++ std::string type or some other type? I don't think there's an explicit string type within C, only arrays of characters. (Like "const char".)
Also, please see the other thread in the forum about GetCString() if this is what you're after.
On 20/02/2004 at 02:15, xxxxxxxx wrote:
Yes this is std::string.
Do u have any idea how to cast from std::string to SDK String ?
Thanks and regards
On 22/02/2004 at 17:15, xxxxxxxx wrote:
This would be one way:
std::string StringToStdString(const String& s, StringEncoding enc = StXbit)
const LONG len = s.GetCStringLen(enc);
CHAR* tmp = new CHAR[len+1];
if (len == s.GetCString(tmp, len+1, enc))
String StdStringToString(const std::string& s, StringEncoding enc = StXbit)
const CHAR* tmp = s.c_str();
r.SetCString(tmp, -1, enc);
Bool MenuTest::Execute(BaseDocument *doc)
String s1 = "Hello World!";
std::string s2 = StringToStdString(s1);
String s3 = StdStringToString(s2);
On 22/02/2004 at 19:01, xxxxxxxx wrote:
Thanks for the reply.
If i printed the CHAR First using GeDebugOut, I will get this result: u)ü
I am a bit lost not. Is That means i have to do like this:
SQLBindCol (hStmt, 1, SQL_C_CHAR, First, sizeof(First), &cbModel);
Seems like to get the String of First, I have tried to do it like:
String s3 = String(First);
But i got the same resule as above as u)ü when i used GePrint to print in the console?
Any hints for me how to solve this?
Thanks and regards
On 22/02/2004 at 19:44, xxxxxxxx wrote:
Are you sure that SQLBindCol has actually put anything sensible into the string? If GeDebugOut() prints "u)ü" then I'd say it's pretty likely that's what is in memory.
By using the debugger I didn't mean GeDebugOut(). Instead, place a breakpoint on the first line (F9 in MSVC), then run the plugin (F5 in MSVC) and see how the memory changes. (You have various debug panels. Check out the documentation of your IDE for more information.)
On 22/02/2004 at 20:19, xxxxxxxx wrote:
I have tried using VC++, my code is:
SQLBindCol (hStmt, 2, SQL_C_CHAR, First, sizeof(First), &cbModel);
then I casted it into c string
string str((const char* ) First);
printf("From the string object: %s\n", str.c_str());
When I printed into the console, I got the correct answer from database.
The problem occures when I tried to cast it into String from C4D, is it correct that I will get the encoded of the str above by using
String s3 = StdStringToString(str);
Thanks and regards
On 22/02/2004 at 20:33, xxxxxxxx wrote:
Ok, then I trust you that SQLBindCol() is not the culprit. Do you mean that the function I provided above cannot correctly convert your std::string into a C4D String? That's very strange. Perhaps it's a zero termination issue. Could you try single stepping the code to see where it goes wrong? (Please tell me if you need help to set up your debug environment. Solving this problem without a debugger might be hard.)
Also, if the string doesn't contain any non-ASCII characters (which at this point sounds like a good thing to do to simplify the debugging), then you could try one of the simpler encodings, e.g. St7bit.
The code I posted above has been tested both in 8.503 and 8.207. You say that you're using 8.1, which is unsupported since 8.2 is a free update. I don't suspect that this would be the problem, but you should try updating to at least 8.2 anyway.
On 29/03/2007 at 03:07, xxxxxxxx wrote: