473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

A problem with BSTR

this is my code:

BSTR A;

//I put data in A and I test it through a message box and all things are alright

MyFunction(A);


//I have an error in my function

when I write this code:

USES_CONVERSION;
OLECHAR desc[23];
char A[23]="mydata";
int i;
for (i=0;i<23;i++)
{
desc[i]=(OLECHAR)A[i];
}
MyFunction(desc)
//the function succeeds

I want to know why the first code doesn't run correctly
this problem frustrate me cuz I know that the use of (OLECHAR*) and (OLECHAR[23]) are similar!!!!!
and the most surprising thing for me than even this dont work

A=desc
MyFunction(A);

please help or give me any idea!!!!
Mar 17 '08 #1
4 2414
weaknessforcats
9,208 Expert Mod 8TB
An OLECHAR is a 16-bit Unicode character. Your message box needs an 8-bit character. The typecase does nothing except tells the compiler to forget that the assignment won't work.

The fundamental error here is in not using TCHAR instead of char. That would mena using all of the TCHAR mappings. You can check MSDN for this.

You cannot reliable mix ASCII and UNICODE in the same Windows program.
Mar 17 '08 #2
well, thx I understand but not a lot


u mean that BSTR which is an OLECHAR*

and OLECHAR array don't use the same type of coding!!!
Mar 17 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
That is correct. An OLECHAR is a typedef for a char and a BSTR is a typedef of an OLECHAR*.

But- a BSTR is a data structure that has a different format than a plain old OLCHAR string.

You have to use the COM Automation string manipulation functions to get a BTSR from a string of OLECHAR.

Read this: http://msdn2.microsoft.com/en-us/lib...05(VS.85).aspx.
Mar 18 '08 #4
Thx now I resole my problem

it was a problem in my function


I have now a good idea about BSTR

thx
Mar 18 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: banski | last post by:
Hi, Im trying to find out how to convert a SYSTEMTIME to BSTR. Cant find out how to do that. Hopefully some of you could help me out. Best regards Thomas
3
by: Volker Kugler | last post by:
Hi, i want to transmit a string from a C++-COM-DLL to C#. I wrote this code: STDMETHODIMP CWinpcap::hrGetAdapterNameFromAdapterNumber(int iAdapterNumber, BSTR * AdapterName) { int index =...
5
by: Michael C | last post by:
I'm trying to convert this interface over to C# but can't get any of the functions to work at all. I'm just trying as a start to get the get_Name function to work but can't get anything out of it...
8
by: Michael Tissington | last post by:
I have a C++ function in a DLL of the form BSTR WINAPI DoSomeWork(LPCSTR szConnection, LPCSTR szGUID) I use SysAllocStringByteLen to return a BSTR. For the most part this works accept when...
0
by: Edwin Knoppert | last post by:
I'm currently using a wrapper which converts an ANSI BSTR from a dll. (Yes, singlebyte but BSTR ! ) This works fine and i'm aware BSTR's returned must be destroyed by the caller, which i do. ...
0
by: Jason Chrin | last post by:
Hello. I've been trying to use a 3rd party API within a console application. The program runs fine, but when it exits, I get a Memory cannot be read error. I've searched for the past few days,...
2
by: Lucy Ludmiller | last post by:
How can I write a function like this: BSTR Greeting(BSTR name) { //return "Good Morning : " + name ; } In short I'm looking for a quick tutorial on using BSTR - Google is not bringing up...
0
by: Jason Smiley | last post by:
So I have a function that is called from a COM object that has a BSTR as an out paramater. A code snippet looks like this: MyComLib.MyComInterface tester = new MyComLib.MyComInterface(); // ...
0
by: SantaClaus | last post by:
Hi all, I'm using a BSTR as an out parameter in a function which reads a file. Here is my code. HRESULT __stdcall CA::getFile(BSTR bstr,BSTR *fileCont) { if (!fileCont) return E_POINTER;...
0
by: sandeepkavade | last post by:
hi all, i am having a sdk with fires an event. i am trying to catch that event in other C++ console application, i have derived my CEventSink class from IDispEventImpl EventSink.h: #pragma...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.