Click here to Skip to main content
15,911,531 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Memory Leaks Detection Pin
Renjith Ramachandran2-Nov-05 3:12
Renjith Ramachandran2-Nov-05 3:12 
QuestionVS NET. 2003 strange characters in MFC project? Pin
9ine1-Nov-05 23:17
9ine1-Nov-05 23:17 
AnswerRe: VS NET. 2003 strange characters in MFC project? Pin
Rob Caldecott1-Nov-05 23:23
Rob Caldecott1-Nov-05 23:23 
AnswerRe: VS NET. 2003 strange characters in MFC project? Pin
9ine1-Nov-05 23:24
9ine1-Nov-05 23:24 
GeneralRe: VS NET. 2003 strange characters in MFC project? Pin
Jörgen Sigvardsson1-Nov-05 23:26
Jörgen Sigvardsson1-Nov-05 23:26 
GeneralRe: VS NET. 2003 strange characters in MFC project? Pin
Prakash Nadar1-Nov-05 23:56
Prakash Nadar1-Nov-05 23:56 
GeneralRe: VS NET. 2003 strange characters in MFC project? Pin
Jörgen Sigvardsson2-Nov-05 0:03
Jörgen Sigvardsson2-Nov-05 0:03 
QuestionStrings really messed up between VC++ and VB Pin
Axonn Echysttas1-Nov-05 22:37
Axonn Echysttas1-Nov-05 22:37 
Hi everybody. I got a question related to an article for the Code Project I'm working at. I got this function in VC++ which returns a structure to VB. The structure contains a long member and a BSTR member. In VB the structure contains a long member and a String member, so their data types are matched. Ok. With the long member, there are no problems.

However, when I put a text in the BSTR member, like this:

cmResponse.theBSTR = SysAllocString(ConvertCharToBSTR("String added in <br />
VC++"));


(I pasted the ConvertCharToBSTR function at the end of this message)
I get the following data back in VB:
"S|t|r|i|n|g| |a|d|d|e|d| |i|n| |V|C|+|+|"

That | is actually some weird character. Of course, I realize this is probably some data type alignment issue. I tried sending char but with no use: VB requires SysAllocString to allocate the string in order to successfully receive it. Also, I think the String type from VB is not UNICODE while C++ sends an Unicode. I did make it work (although this is not entirely correct) like this:

LPCWSTR test = (LPCWSTR)"testing";<br />
cmResponse.sFifth = SysAllocString(test);


However, because "testing" has 7 letters, I get an eight character in VB : "|". So in VB it looks like this "testing|". If I write "testin" it's ok since it has 6 characters.

So what could be the problem? How can I do it to get this string correctly to VB? So far, the only solution I can figure out is to allocate a number of characters equal to the lenght of the string divided by 2 using SysAllocString, then if the string has an un-even number of characters, add a space to it. Which of course is an ugly solution.

Here's the ConvertCharToBSTR function, for all that matters...
//Converts a Char to a BSTR. Needed when working with strings with Visual Basic.<br />
BSTR ConvertCharToBSTR(char* CharValue)<br />
{<br />
	int i; //Iteration counter.<br />
	int iLength = strlen(CharValue); //Finding out the length of the Char.<br />
	unsigned short* bstrResult = new unsigned short[iLength + 1]; //Creating a BSTR with the required length.<br />
<br />
	//Going through the Char characters.<br />
	for (i = 0; i < iLength; i++)<br />
	{<br />
		char iCharacter = CharValue[i]; //Taking the next char.<br />
		bstrResult[i] = iCharacter; //Adding it to the string.<br />
		bstrResult[i + 1] = '\0'; //Adding the null-termination to the string.	<br />
	}<br />
	return bstrResult; //Returning the result.<br />
}


-= E C H Y S T T A S =-
The Greater Mind Balance
AnswerRe: Strings really messed up between VC++ and VB Pin
Prakash Nadar1-Nov-05 23:03
Prakash Nadar1-Nov-05 23:03 
GeneralRe: Strings really messed up between VC++ and VB Pin
Axonn Echysttas1-Nov-05 23:44
Axonn Echysttas1-Nov-05 23:44 
GeneralRe: Strings really messed up between VC++ and VB Pin
Prakash Nadar1-Nov-05 23:52
Prakash Nadar1-Nov-05 23:52 
GeneralRe: Strings really messed up between VC++ and VB Pin
Axonn Echysttas2-Nov-05 0:50
Axonn Echysttas2-Nov-05 0:50 
GeneralRe: Strings really messed up between VC++ and VB Pin
Prakash Nadar2-Nov-05 4:55
Prakash Nadar2-Nov-05 4:55 
GeneralRe: Strings really messed up between VC++ and VB Pin
Axonn Echysttas2-Nov-05 7:00
Axonn Echysttas2-Nov-05 7:00 
GeneralRe: Strings really messed up between VC++ and VB Pin
Prakash Nadar2-Nov-05 15:33
Prakash Nadar2-Nov-05 15:33 
AnswerRe: Strings really messed up between VC++ and VB Pin
Jörgen Sigvardsson1-Nov-05 23:29
Jörgen Sigvardsson1-Nov-05 23:29 
GeneralRe: Strings really messed up between VC++ and VB Pin
Axonn Echysttas2-Nov-05 3:26
Axonn Echysttas2-Nov-05 3:26 
GeneralRe: Strings really messed up between VC++ and VB Pin
Jörgen Sigvardsson2-Nov-05 3:35
Jörgen Sigvardsson2-Nov-05 3:35 
GeneralRe: Strings really messed up between VC++ and VB Pin
Axonn Echysttas2-Nov-05 4:26
Axonn Echysttas2-Nov-05 4:26 
AnswerRe: Strings really messed up between VC++ and VB Pin
S Douglas2-Nov-05 20:26
professionalS Douglas2-Nov-05 20:26 
QuestionDirect Show RenderStream from Capture pin to compression and AVI mux Pin
sumits1-Nov-05 22:10
sumits1-Nov-05 22:10 
Questionresizing a window Pin
hamidreza_buddy1-Nov-05 21:25
hamidreza_buddy1-Nov-05 21:25 
AnswerRe: resizing a window Pin
Prakash Nadar1-Nov-05 21:43
Prakash Nadar1-Nov-05 21:43 
AnswerRe: resizing a window Pin
FarPointer1-Nov-05 22:19
FarPointer1-Nov-05 22:19 
Questionusing activex controls HELP Pin
hamidreza_buddy1-Nov-05 21:22
hamidreza_buddy1-Nov-05 21:22 

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.