Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2274
  • Last Modified:

How to Convert BSTR to Byte Array in VC++ ???

Hi All,
  Can anybody provide me a simple routine to convert BSTR to byte array in VC++ ?

Any help will be really appreciated.

Regards,
Manjesh
0
Manjesh
Asked:
Manjesh
1 Solution
 
novitiateCommented:
You can simply do this, or use One of WideCharToMultiByte functions.

#include <comdef.h>
#include <atlbase.h>
#include <iostream>

typedef unsigned char byte;
//#include <oleauto.h>

int main(void) {
      
      BSTR str = SysAllocString(L"Hello World");
      byte data[256];

      int len = SysStringLen(str);

      for(int i = 0; i < len; ++i)
      {
            data[i] = (byte)str[i];
      }
      data[i] = '\0';
      std::cout << data;
      return 0;
      
}

_novi_
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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