• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 785
  • Last Modified:

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

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
NomanAhmed
Asked:
NomanAhmed
  • 2
2 Solutions
 
Infinity08Commented:
string ABC(OLECHAR * str){

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

}
0
 
Infinity08Commented:
0
 
bijopuliCommented:
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
 
Deepu AbrahamR & D Engineering ManagerCommented:
You can use A2T,A2OLE Macros for conversion
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now