Solved

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

Posted on 2007-04-03
4
766 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 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

Independent Software Vendors: 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 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