Hello afriza, thanks for your quick replay. if i use the WCHAR or std'::wstring, should i used the _UNICODE macro in the Visual Studio Project setting?
best regards ming On 16.12.2010 17:34, Afriza N. Arief wrote: > @Cory: correct. > > Fixed Code: > > HWND hWnd = /* from somewhere */; > int nLen = GetWindowTextLength(hWnd) + 1; > WCHAR* lpszText = (WCHAR*)malloc(nLen*sizeof(WCHAR)); > // std::wstring str; str.resize(nLen); > nLen = GetWindowText(hWnd,lpszText,nLen); > // str.resize(nLen=GetWindowText(hWnd,&str[0],nLen)); > sqlite3_bind_text16(stmt,1,lpszText,nLen*sizeof(WCHAR),SQLITE_TRANSIENT); > // (.., str.data(),nLen*sizeof(std::wstring::value_type),SQLITE_TRANSIENT); > free(lpszText); // not needed for std::wstring > > When you first time create the database, use sqlite3_open() to store > the data as utf8. I believe bind_text16() will convert from utf16 to > utf8 for you. > > See: > - GetWindowTextLength() http://msdn.microsoft.com/en-us/library/ms633521.aspx > - GetWindowText() http://msdn.microsoft.com/en-us/library/ms633520.aspx > - sqlite3_bind_text16() http://www.sqlite.org/c3ref/bind_blob.html > > Note: > - You need your project to be compiled in UNICODE > > On Fri, Dec 17, 2010 at 12:24 AM, Cory Nelson<phro...@gmail.com> wrote: >> Just a quick note -- TCHAR is not always UTF-16, and >> sqlite3_bind_text16 takes a void* so it will happily take whatever you >> give it. You should be using wchar_t directly instead of TCHAR, so an >> error can be caught when you use GetWindowText. >> > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users