Solved

using variable value in SysAllocString(L"6393570000001130");  inplace of Hard coded "6393570000001130"  in C++

Posted on 2007-04-03
4
756 Views
Last Modified: 2008-01-09
I need to call SysAllocString() function and get BSTR value I have a code like this

 BSTR Key = SysAllocString(L"6393570000001130");
 long  resultFromVB  = t->ShowForm(&Key);

in above code I dont want to hard coded value "6393570000001130" instead of this I want to put variable in it which is updated dynamically when this method is called in which above code is written
for example

string ABC(string str){

 BSTR Key = SysAllocString(Lstr);
 long  resultFromVB  = t->ShowForm(&Key);

}
when I do above this I get an error what should I do
0
Comment
Question by:NomanAhmed
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 75 total points
ID: 18842064
string ABC(OLECHAR * str){

 BSTR Key = SysAllocString(str);
 long  resultFromVB  = t->ShowForm(&Key);

}
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18842086
0
 
LVL 6

Assisted Solution

by:bijopuli
bijopuli earned 50 total points
ID: 18842233
Hi NomanAhmed

 U can get this job done using the _bstr_t wrapper class.

Try this:

      string str;

      BSTR MyBSTR;

      str="Hi how are u";

      _bstr_t tempbstr(str.c_str());

      MyBSTR = tempbstr; //now MyBSTR is allocated

      ::SysFreeString(MyBSTR); //deallocating after use


Dont forget to include

#include <comdef.h>
#include <string>

Regards
Bijo.
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18842556
You can use A2T,A2OLE Macros for conversion
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question