Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6716007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:40:54+00:00 2026-05-26T08:40:54+00:00

I have a function to write file a BSTR, but I can not write

  • 0

I have a function to write file a BSTR, but I can not write it to a file with encoding include? Here is my function, please correct for me!

unsigned long Vnpt_WriteFile(const LPCTSTR pFilePath, const BYTE* pbData, const DWORD cbData)
{
    DWORD numbytes = 0;
    unsigned long rv = 0;
    FILE*   fileHandle;

    HANDLE fh = CreateFile(pFilePath, FILE_WRITE_DATA,0,NULL,CREATE_ALWAYS,0,NULL);
    if (fh == INVALID_HANDLE_VALUE){
        rv = CKR_CREATE_FILE_ERROR;
        return rv;
    }

    if(!WriteFile(fh, pbData, cbData, &numbytes, NULL)){
        rv = CKR_WRITE_FILE_ERROR;
    }
    CloseHandle(fh);
    return rv;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:40:55+00:00Added an answer on May 26, 2026 at 8:40 am

    BSTR are wide char (wchar_t) strings. You should have no problem writing them into a file using general purpose functions as WriteFile. Only problem you’ll have is with viewing the file with some text editor. To solve that, you have to place a Byte Order Mark (BOM) at the beginning of the file, before you write the actual content. This will indicate the file’s content to text editor. Note, however, that you’ll have to be aware of that when you read the file’s content – it will contain that BOM before the text.

    You can do something along these lines (unchecked):

    unsigned char BOM[2] = {0xFF, 0xFE};
    WriteFile(fh, BOM, 2, &numbytes, NULL);
    

    right after you create the file, and before you write the BSTR’s content.

    Late addition, just to clarify my first sentence: a BSTR is not exactly an array of wchar_ts, but for the sake of writing its content to a file, it is ok to treat it as such. For more on this, read Eric’s Complete Guide To BSTR Semantics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a little DBQuery function in perl so I can have
I have a function that lets me write the file-path of files to a
I have a function: def save(self, text, *index): file.write(text + '\nResults:\n') if index ==
I have a file in my project folder.How i can i give file write
I have a php function I wrote that will take a text file and
I have a function that calls out a read or write request on a
how to write a function from list to a tuple i have taken the
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
I'd like to write a function that would have some optional code to be
If you have a C function which returns an integer, you could write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.