We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,382 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

HELP | Convert CString to char | Unicode

Hello everybody i'am building a software to make lab management. So I need to save the data base. and i using SQLite. but I have problem the SQLite pramter is a const char. and the data from the software are CString. and becouse I using Unicode I can't convert them normally. I really need some function to convert from CString - Unicode. To char / const char, and other side.

Please. Tks biny.

4
Contributors
7
Replies
7 Months
Discussion Span
1 Year Ago
Last Updated
8
Views
Question
Answered
l1nuxuser
Newbie Poster
20 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Which CString? Sadly, there's more than one library with a class called CString, and they all work slightly differently.

Narue
Bad Cop
Team Colleague
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54

For Microsoft MFC CString to char*, see this post. Just use CString's GetBuffer() to get the pointer to the wchar_t*.

Ancient Dragon
Achieved Level 70
Team Colleague
32,155 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

First of all tks lot. And I meen for MFC class. And for you ancient I need to know if the link you gave need the all local include are locate ther. Because ther is no link for it

l1nuxuser
Newbie Poster
20 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Would you clarify your question because I don't know what you asked???

Scroll down to the section titled "Converting from wchar_t*". Pay attention to the functions that are used, especially wcstombs_s().

Ancient Dragon
Achieved Level 70
Team Colleague
32,155 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

sure, soory.

this include!

#include "atlbase.h"
#include "atlstr.h"
#include "comutil.h"
l1nuxuser
Newbie Poster
20 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

tnk U!!!!!!! i done it its perfect.

i even make libray to make simple. for anyone stuck in this stuff, you can download it via the link below.

Attachments cfstringchar.zip (0.8KB)
l1nuxuser
Newbie Poster
20 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Years Ago by Ancient Dragon and Narue

CString str = "hello";
char* strBuf = new char[20];
int i = 0;
for(int i = 0 ; i < str.GetLength(); i++)
{
strbuf = str;
}
strBuf = NULL;
/*this code is for unicode mfc vc++
and it works.

kndubey88
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0751 seconds using 2.66MB