0

I am passing LPWSTR as a reference in a method. The value remains in method but in callee function, it gets lost. I suspect I need to give some memory to LPWSTR but I am unable to figure out the method to do it. This is how my code looks like:

ValidateUrl(LPCWSTR wzSomeUrl, LPWSTR& DecodeUrlOut) {

    /* 
     I decode wzSomeUrl and put value in DecodeurlOut
    */

}

LPWSTR DecodeUrlOut = NULL;
ValidateUrl(wzSomeUrl , DecodeUrlOut);

I debug and find that DecodeUrlOut's value is L"".

  • The problem is somewhere in the code you haven't shown. If I had to guess, I'd suspect you make `DecodeUrlOut` point to a local variable, which is destroyed when the function returns, leaving `DecodeUrlOut` a dangling pointer. – Igor Tandetnik Jan 12 '17 at 05:28
  • 1
    visit [a link]http://stackoverflow.com/questions/4137672/passing-lpcwstr-by-reference. – Rohit Hajare Jan 12 '17 at 06:21
  • @RohitHajare - Yeah this is same issue I am facing. I believe the problem is because of scopeof variable as mentioned in link you shared. Changing LPWSTR to wstring. Thanks for sharing the link. Will update if it works. – Richa Aggarwal Jan 12 '17 at 06:30
  • Changing the type of DecodeUrlOut to wstring fixed the issue for me. Thanks Rohit!! – Richa Aggarwal Jan 12 '17 at 08:30

0 Answers0