Click here to Skip to main content
15,888,521 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to forward delare CArray class ? Pin
VCSharp00726-Jun-07 20:21
VCSharp00726-Jun-07 20:21 
AnswerRe: How to forward delare CArray class ? Pin
CPallini26-Jun-07 20:50
mveCPallini26-Jun-07 20:50 
AnswerRe: How to forward delare CArray class ? Pin
Nibu babu thomas26-Jun-07 21:00
Nibu babu thomas26-Jun-07 21:00 
GeneralRe: How to forward delare CArray class ? Pin
VCSharp00726-Jun-07 22:31
VCSharp00726-Jun-07 22:31 
GeneralRe: How to forward delare CArray class ? Pin
Nibu babu thomas26-Jun-07 22:39
Nibu babu thomas26-Jun-07 22:39 
AnswerRe: How to forward delare CArray class ? Pin
KarstenK26-Jun-07 21:28
mveKarstenK26-Jun-07 21:28 
QuestionEnumerating Installed Apps with MSI Pin
Akin Ocal26-Jun-07 20:13
Akin Ocal26-Jun-07 20:13 
QuestionBSTR in C++ Pin
Axonn Echysttas26-Jun-07 19:45
Axonn Echysttas26-Jun-07 19:45 
Hi everybody. I got a tiny question about a strange problem I'm having when I'm trying to receive a string from Visual Basic into C++. I got a VB string saying "Arial". But when I'm receiving it in C++, it becomes "Ail". Probably some wide characters versus normal characters problem, as i get 1 character and the next not, and then the next, I get. In order to make the conversion I'm using these two functions.

<br />
<br />
//Finds out the length of a BSTR.<br />
long GetLengthOfBSTR (BSTR Target)<br />
{<br />
	long iRet = 0; //Result to return.<br />
	long iCursor = 0; //Interator through the BSTR.<br />
	bool bForever = false; //To cycle forever.<br />
	<br />
	//If the string is NULL.<br />
	if (Target == NULL)<br />
		return(0); //Returning zero length.<br />
	while (!bForever) //Cycling forever.<br />
	{<br />
		unsigned int uiPiece = Target[iCursor]; //Piece by piece.<br />
		//Until reaching the null termination of the string.<br />
		if (uiPiece == 0)<br />
			return(iRet); //Returning the computed length.<br />
		else<br />
			iRet++; //Increasing the length.<br />
		iCursor++; //Increasing the BSTR iterator.<br />
	}<br />
	return -1; //Mostly to avoid warnings ::- ).<br />
}<br />
<br />
//Converts a BSTR to a Char. Needed when working with strings with Visual Basic.<br />
char *ConvertBSTRToChar (BSTR Target)<br />
{<br />
	char *sResult; //Result to return.<br />
	long iCounter; //Iterator.<br />
	long iLength; //Length of Target.<br />
	<br />
	iCounter = iLength = GetLengthOfBSTR(Target); //Initializing.<br />
	sResult = new char[iLength + 1]; //Creating a character big enough to hold the result.<br />
	strcpy(sResult, ""); //Initializing.<br />
	for (iCounter = 0; iCounter < iLength; iCounter++) //Going through the Target BSTR.<br />
	{<br />
		unsigned int uiPiece = Target[iCounter]; //Taking it piece by piece.<br />
		sResult[iCounter] = uiPiece; //Adding it in the final result.<br />
		sResult[iCounter + 1] = '\0'; //Adding null termination.<br />
	}<br />
	return sResult; //Returning computed char.<br />
}<br />


And then I do:

<br />
LPCSTR c;<br />
c = ConvertBSTRToChar(StuffFromVB);<br />
MessageBox(0, c, "Test", 0);<br />


SO? Anybody here to enlighten me a bit about this? : ). Thank you very much for your time here anyway!

-= E C H Y S T T A S =-
The Greater Mind Balance

Blending C++ with COM ^

AnswerRe: BSTR in C++ Pin
Nibu babu thomas26-Jun-07 20:10
Nibu babu thomas26-Jun-07 20:10 
GeneralRe: BSTR in C++ Pin
Axonn Echysttas26-Jun-07 20:52
Axonn Echysttas26-Jun-07 20:52 
GeneralRe: BSTR in C++ Pin
Nibu babu thomas26-Jun-07 21:06
Nibu babu thomas26-Jun-07 21:06 
AnswerRe: BSTR in C++ Pin
Arman S.26-Jun-07 20:16
Arman S.26-Jun-07 20:16 
GeneralRe: BSTR in C++ Pin
Axonn Echysttas26-Jun-07 20:48
Axonn Echysttas26-Jun-07 20:48 
GeneralRe: BSTR in C++ Pin
CPallini26-Jun-07 21:06
mveCPallini26-Jun-07 21:06 
GeneralRe: BSTR in C++ Pin
CPallini26-Jun-07 21:03
mveCPallini26-Jun-07 21:03 
GeneralRe: BSTR in C++ Pin
Randor 27-Jun-07 8:38
professional Randor 27-Jun-07 8:38 
AnswerRe: BSTR in C++ Pin
Randor 27-Jun-07 8:48
professional Randor 27-Jun-07 8:48 
GeneralRe: BSTR in C++ Pin
Axonn Echysttas27-Jun-07 9:24
Axonn Echysttas27-Jun-07 9:24 
GeneralRe: BSTR in C++ Pin
Randor 27-Jun-07 17:03
professional Randor 27-Jun-07 17:03 
GeneralRe: BSTR in C++ Pin
Axonn Echysttas27-Jun-07 21:47
Axonn Echysttas27-Jun-07 21:47 
QuestionCPropertySheet::DoModal and focus problem Pin
rp_suman26-Jun-07 19:42
rp_suman26-Jun-07 19:42 
QuestionRe: CPropertySheet::DoModal and focus problem Pin
prasad_som27-Jun-07 0:53
prasad_som27-Jun-07 0:53 
AnswerRe: CPropertySheet::DoModal and focus problem Pin
rp_suman1-Jul-07 18:10
rp_suman1-Jul-07 18:10 
QuestionDocking Dialog Bar Pin
g_sandipan26-Jun-07 19:17
g_sandipan26-Jun-07 19:17 
AnswerRe: Docking Dialog Bar Pin
Nibu babu thomas26-Jun-07 19:34
Nibu babu thomas26-Jun-07 19:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.