|
Yeah..However If I can get some help on my bitmap issue. this will not be required.
trying hard to get this going it was one of the main reasons I moved to C++. Was strugling with it in VB for the last3 to 4 months and I think I might have this solved with a little more help.
Thanks a million. I do appreciate all the help from everyone here.
|
|
|
|
|
Hello all... I've Win32 application in which i extract data from database and put into some file..Say notepad.. I'm facing problem in extracting chinese fonts..
For ex if the entry in database is "Abc (Some chinese stuff)" after extraction it comes "Abc ???????" in buffer...
How do i properly extract chinese character in VC++ ??
Thanks all...
|
|
|
|
|
You probably need to use unicode.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
This is what i'm doing...
_bstr_t bstrString_Ini;
_bstr_t bstrString_Tag;
_bstr_t bstrString_Dest;
char sqlQuery[2 * MAX_PATH] = "";
sprintf(sqlQuery, "SELECT IniSection,TagName,DestinationValue FROM %s WHERE FileName = '%s'" , szTableName, szstr);
_bstr_t sqlQueryText(sqlQuery);
try
{
ADODB::_CommandPtr m_objCmdSearch;
ADODB::_RecordsetPtr m_cpRecordsetSearch;
HRESULT hr = m_objCmdSearch.CreateInstance("ADODB.Command");
if(SUCCEEDED(hr))
{
m_objCmdSearch->ActiveConnection = m_cpConnection;
m_objCmdSearch->CommandType = ADODB::adCmdText;
m_objCmdSearch->CommandText = sqlQueryText;
m_cpRecordsetSearch = m_objCmdSearch->Execute(NULL, NULL, ADODB::adCmdText);
if(m_cpRecordsetSearch != NULL)
{
if(!m_cpRecordsetSearch->GetEndOfFile())
{
char szstr[MAX_PATH];
char szstr1[MAX_PATH];
m_cpRecordsetSearch->MoveFirst();
while(!m_cpRecordsetSearch->EndOfFile)
{
bstrString_Ini = m_cpRecordsetSearch->Fields->GetItem("IniSection")->GetValue().bstrVal;
bstrString_Tag = m_cpRecordsetSearch->Fields->GetItem("TagName")->GetValue().bstrVal;
bstrString_Dest = m_cpRecordsetSearch->Fields->GetItem("DestinationValue")->GetValue().bstrVal;
m_cpRecordsetSearch->MoveNext();
}
rVal = TRUE;
}
if((m_cpRecordsetSearch->State & ADODB::adStateOpen) != 0)
{
m_cpRecordsetSearch->Close();
m_cpRecordsetSearch = NULL;
}
}
m_objCmdSearch->PutRefActiveConnection(NULL);
}
}
And i get "Abc ????" in bstrString_Dest... Which is defined as _bstr_t...
bstrString_Dest = cpRecordsetSearch->Fields->GetItem("DestinationValue")->GetValue().bstrVal;
What else do i need to do.. I've enabled unicode in my project..
|
|
|
|
|
How did you determine what is in that variable (traced it out, pointed at it and checked the tooltip in VS, ...)? Are you sure the database correctly contains the chinese chars?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Yes i'm sure that database correctly contain chinese char (I saw it).. And i can see the value of that variable in tooltip only.. Other int values comes out perfect but this chinese stuff which is in last field, it only shows "????"..
Am i missing some setting or do i need to use other data type ?
Thanks
|
|
|
|
|
I'm not sure but i suspect that the tooltip simply doesn't handle the chinese chars...try to save the string into a txt file for example and then open it in word or such and see if it displays the chinese chars or not (you might need to select the right charset to actually see something usefull).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I tried.. I printed all the results into text file but result remains same.. some text in English followed by question mark...
I even tried putting in MS-Word file..But same result..
|
|
|
|
|
What happens if you retrieve the string into CString instead of _bstr_t ? Btw if you check out the string as a byte array, what do you get at the place of questionmarks? Can you maybe upload that text file somewhere for me so i can take a peak?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I can't use CString ... Not using MFC ..
Is there any subsitute of CString in Win32 ???
Thanks..
|
|
|
|
|
Hmm, am not sure...how about std:string ?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Try outputting the string and check whether it is really some junk characters or you were just unable to view it properly.
You could do this.
MessageBox(0, (wchar_t*)bstrvariable, 0, 0);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
That give some hope..When i use MessageBoxW it doesn't give "????" , rather that it give some junk character (Might be chinese which is not supported in messagebox).. Trying to print into notepad..
|
|
|
|
|
I believe the characters are encoded in the multi-byte character set.
So you should first extract the characters into a char array instead of wchar_t array or string variable instead of wstring variable or you can explicitly use CStringA instead of CString .
After getting it into the variable, convert the multi-byte characters into wide characters using the MultiByteToWideChar API.
Now use that in a MessageBoxW function.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I just did this to print data on file...
(char *)(wchar_t*)bstrString_Dest
And it's printing chinese character... That was just a blind try..how did it work..Can someone explain?
|
|
|
|
|
I did this...
bstrString_Dest = m_cpRecordsetSearch->Fields->GetItem("DestinationValue")->GetValue().bstrVal;
Extracted the character in char array..
strncpy(bstrString_Dest_Char,(char*)bstrString_Dest, sizeof(bstrString_Dest_Char));
Converted using MultiByteToWideChar..
TCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, bstrString_Dest_Char, -1,
(wchar_t*)wsz, MAX_PATH);
Printed using Messagebox
MessageBoxW(0, (wchar_t*)wsz, 0, 0);
But same result
|
|
|
|
|
Use wchar_t instead of TCHAR
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
<quote>Use wchar_t instead of TCHAR
Changed it to this
wchar_t wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, bstrString_Dest_Char, -1,wsz, MAX_PATH);
MessageBoxW(0, wsz, 0, 0);
and this..
wchar_t wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, bstrString_Dest_Char, -1,(wchar_t*)wsz, MAX_PATH);
MessageBoxW(0, wsz, 0, 0);
But Same result...Gossh what am i doing wrong?
|
|
|
|
|
|
My final try.
Try CP_UTF8 instead of CP_ACP .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Sadly that didn't work either.. Anyways thanks for your help..
|
|
|
|
|
MessageBox(0, (wchar_t*)bstrvariable, 0, 0);
I guess this is giving me right data...
How do i print this to file.. Notepad??
Thanks..
|
|
|
|
|
I need help with this code I can't seem to get it right please help.
#include<iostream>
#include<string>
using namespace std;
enum gameName{odd, even};
void displayRules();
gameName retrievePlay(int selection);
bool valdSelection(char selection);
void convertEnum(gameName odject);
gameName winningOdject(gameName play1, gameName play2);
void gameResult(gameName play1,gameName play2, int& winner);
void displayResults(int gCount, int wCount1, int wCount2);
int main ()
{
int selection;
int play1, play2;
int sum;
int gameCount;
int winCount1, winCount2;
int num[5];
int counter;
int gamewinner;
char response;
int selection1, selection2;
int gamePlay1;
int gamePlay2;
gameCount = 0;
winCount1 = 0;
winCount2 = 0;
displayRules();
cout << "Enter Y|y to play the game: ";
cin >> response;
cout << endl;
while ( response == 'Y' || response == 'y')
{
cout << "Player1 enter your choice: ";
cin >> selection1;
cout << endl;
cout << "player2 enter your choice: ";
cin >> selection2;
cout << endl;
if ( valdSelection(selection1) && valdSelection(selection2))
{
play1 = retrievePlay(selection1);
play2 = retrievePlay(selection2);
gameCount++;
gameResult(play1, play2, gamewinner);
if (gamewinner == 1)
winCount1++;
}
cout << "Enter Y | y to play the game: ";
cin >> response;
cout << endl;
}
displayResults(gameCount, winCount1, winCount2);
for ( counter = 0; counter < 5; counter++)
cin >> num[counter];
sum = sum + num[counter];
cout << endl;
return 0;
}
void displayRules();
{
cout << "Hi and welcome to the game Odds and Evens." << endl;
cout << "This is a game for one or two players." << endl;
cout << "The rules of the game are has follows:" << endl;
cout << "1. the players choise either Odds or Evens." << endl;
cout << "2. The players choise a number between 1 and 5." << endl;
<< "3. After player choise there number. " <<endl;
<< "The sum of the numbers either equal a odd number of an even number." << endl;
cout << "The winner is the player that has the right choise." << endl;
}
gameName winningOdject(gameName play1, gameName play2, odd, even)
{
if ((play1 == odd)&& (play2 ==even)||
(play2 == odd) && (play1 == even));
return odd;
if (( play1 == even) && (play2 == even) ||
( play2 == even) && (play1 == even));
return even;
}
void gameResult(gameName play1, gameName play2 ,int& winner)
{
gameName winnerOdject;
winnerOdject = winningOdject(play1, play2);
cout << "Player1 selected: ";
convertEnum(play1);
cout << " and Player2 selected: ";
convertEnum(play2);
cout << " ";
if( play1 == winnerOdject)
winner = 1;
if (play2 == winnerOdject)
winner = 2;
cout << "Player " << winner << " wins this game." <<endl;
}
void displayResults(int gCount, int wCount1, int wCount2)
{
cout << "The total number of games: " << gCount << endl;
cout << "The number of games won by player1: " << wCount1 << endl;
cout << "The number of games won by player2: " << wCount2 << endl;
}</pre>
|
|
|
|
|
so, what is the problem ? does it compile ? does it give wrong answers ? having problem with the logic ?
for example :
if (gamewinner == 1)
winCount1++;
so what happens with player 2 ? doesn't she ever win ?
This signature was proudly tested on animals.
|
|
|
|
|
The answer to the question is that it dose not complier. I have 3 errors like
'gameResult' : cannot convert parameter 1 from 'int' to 'gameName'.
|
|
|
|