Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now