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 7680125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:02:23+00:00 2026-05-31T18:02:23+00:00

I hope the title was good enough to help explain what I am having

  • 0

I hope the title was good enough to help explain what I am having problems with. I think once I solve this problem my project will be pretty much finished. Just a note, both projects are compiled under Unicode.

I am working with a CLI/C++ DLL that takes in a LPCTSTR and returns a const char*. If I store the value of the return in a const char* in my project while stepping through I can see the value its returning is what I expect to be returned.

Now if I do the following:

LPCTSTR strValue = L"test";
const char* Return = MethodCall(strValue);
LPCTSTR Final = CString(Return);

Return will equal “Xmkk=Asmks” (which is what it should). This method encrypts a string. The problem is when I do CString, Final will equal “ﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮﻮ㹙癞鞮᠀諸²⤐²”. How do I turn the onst char* into a LPCTSTR without changing its data”

Thank you.

  • 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-31T18:02:25+00:00Added an answer on May 31, 2026 at 6:02 pm

    After CString(Return) is destructed (this happens “right on next line after its construction”) “Final” pointer is pointing to dealocated chunk of memory (which was internal CString(Return) buffer). At this point contents of memory to which it points is undefined and dereferencing it is undefined behaviour.
    To use pointer to internal buffer safelly you should ensure that CString which owns buffer is alive as long as pointer is.

    
    LPCTSTR strValue = L"test";
    const char* Return = MethodCall(strValue);
    LPCTSTR PointerToBuffer= 0;
    {
      CString ReturnStringObj(Return);
      PointerToBuffer = ReturnStringObj;  
      // Can safelly use your pointer here  
    }
    // Here ReturnStringObj is killed and pointer dereferencing is invalid here
    
    
    
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope my question is clear from the title. But still I will explain
I hope the title is chosen well enough to ask this question. Feel free
Title is bad, Hope the example will clarify this. I have an event. Event
since my title is buzzword compliant I hope I will get lots of answers
(I hope this is a valid question) As I stated in my title, I'm
Hope you're having a good Friday and stuff... okay, so here's my question: All
Hope I'm asking this correctly: I have a project Projects.Client I have my class
I'm not even sure about how to title this qn. But, hope there is
I hope the title of this question makes sense. What I want to know
I hope this title makes sense - I need case-insensitive regex matching on BlackBerry

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.