|
or a version pirated from China
-prakash
|
|
|
|
|
Mine's a pure and legal MSDN Universal copy. Still Chinese by default.
--
|
|
|
|
|
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...
BSTR ConvertCharToBSTR(char* CharValue)<br />
{<br />
int i;
int iLength = strlen(CharValue);
unsigned short* bstrResult = new unsigned short[iLength + 1];
<br />
for (i = 0; i < iLength; i++)<br />
{<br />
char iCharacter = CharValue[i];
bstrResult[i] = iCharacter;
bstrResult[i + 1] = '\0';
}<br />
return bstrResult;
}
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
ConvertCharToBSTR looks very messy function, could you not consider using _bstr_t[^]
-prakash
|
|
|
|
|
Doesn't work.
I put:
_bstr_t sTest = "Testing";<br />
cmResponse.sFifth = sTest;
Where sFifth is a _bstr_t. The VB application crashes when doing so.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote: cmResponse.sFifth = sTest;
cmResponse.sFifth = sTest.Detach(); is the right way to use it
sFifth should also be BSTR
-prakash
-- modified at 5:53 Wednesday 2nd November, 2005
|
|
|
|
|
Hm.
error C2039: 'Detach' : is not a member of '_bstr_t'
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
did you include comutil.h ?
-prakash
|
|
|
|
|
Of course I did! : ). Anyway, the right way to do it is _variant_t, just thought you people want to know. With that it works ok, even if there are still some minor issues.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote: Anyway, the right way to do it is _variant_t
ofcource I know that, But since BSTR worked for you in the first place I was keeping the solution simple for you.
-prakash
|
|
|
|
|
Ehm. You really need to read this[^] and this[^], because you're really on thin ice (about 40 Angstrom thick) when it comes to string handling right now...
--
|
|
|
|
|
Thanks. Yeap, I looked over it and I found the _variant_t type to help me. However, I would prefer being able to use the basic types such as LPCWSTR to solve the problem. Sending LPCWSTR to VB works but if sending un-even number of characters such as "a" or "abc" it adds that | character at the end. If I could solve this in an easy way it would be perfect.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
You get the errors most likely because you are forcing an ASCII string into SysAllocString(). Try this instead: SysAllocString(L"This is a wide string") . Notice the L-prefix?
If you are using MFC7/ATL7.x, you could use CComBSTR() as it takes an ordinary ASCII string as parameter in one of its constructors. Otherwise, please look up the function MultiByteToWideChar() which performs ASCII -> wide for you.
Also, please be wary when dealing with BSTR strings. They are not regular wide strings as the articles I mentioned above says.
--
|
|
|
|
|
Yeah, it's pretty weird. I get a thousand weird issues while working with Strings from VC++ to VB. Very annoying.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Right or wrong I use LPCSTR all the time. I suppose even LPSTR would work also.
Works without any issues.
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
|
Hi Gurus,
I am just trying out to build an application where DirectShow is used for capturing video and audio file.
I have used the Graph Edit given in DirectX9.0 and tried out the concept.
But when i create an application
ICaptureBuilder2 interface and video compression and video capture device and AviMux interface are created or retrieved correctly.
But when i try to use
ICaptureBuilder2 *pBuilder;
IBaseFilter *pVideo;
IBaseFilter *pCompressor;
IBaseFilter *pMux;
// Assume all the above filters are instatiated and retrieved.
HRESULT hr= pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_VIDEO,
pVideo,pCompressor,pMux);
It fails becoz it cannot connect the right pins.
I know that a smart tee filter is inserted after the capture device because of the Intelligent Connect properties.
I am somehow not able to connect the compressor in between.
Can someone help me and clearify what i should do.
thanks in advance
Sumit
|
|
|
|
|
how should i change the size of a window.?? i want to do it in my code.
|
|
|
|
|
hamidreza_buddy wrote: how should i change the size of a window.?? i want to do it in my code.
SetWindowPos[^]
-prakash
|
|
|
|
|
MoveWindow(),CenterWindow(), these might help you along with
CalcWindowRect().
|
|
|
|
|
hi
i want to use an .ocx control in my application. how should i embed it ??
plz help. just say what resources do i need to study to do it?
thx
|
|
|
|
|
If you are developing a MFC application embedding a control is quite simple. You simply have to register it and then add it to your project. Using the class wizard you can easily do the rest, access methods and properties or catch events.
You can find an example here
|
|
|
|
|
Hai..
GetKeyNameText function returns the name of the key pressed in the keyboard. It works fine for the English lanuguage. Now i changed to Language setting to Japanese. If i press a character in the keyboard that should give the japanese name of the character i have pressed. Is there any function works like that?
Please let me know any body have idea.
Regards
Raghavendra
Raghavendra
|
|
|
|
|
Maybe because the keyboard itself was not changed to Japanese, you still get the 'English' names for the keyboard. Try using a Japanese keyboard with a Japanese OS language setting and see if your results are better (you might even need the Japanese version of Windows installed specifically). As I recall, the keyboard names come from the keyboard driver, not from Widnows itself, therefore, if you do not change the keyboard driver out, then you will get names matching keyboard, regardless of the OS localization setting.
|
|
|
|
|
object* Function()const;
when are they called? whats their use? please explain the syntax someone
rahul
|
|
|
|
|