Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-03
4
Medium Priority
?
777 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 225 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 150 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:Deepu Abraham
ID: 18842556
You can use A2T,A2OLE Macros for conversion
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 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