We help IT Professionals succeed at work.
Get Started

Problem with char* and convering to WCHAR

ptrennum asked
Last Modified: 2013-12-04
I'm using VS .NET 2005 and for some reason the variable filename which is a char* is getting populated with Garbage and the variable wideFilename is not being being found???  filename is being passed into the function as a parameter like so:
     Sound( "./Assets/Sound.wav" );  //filename=./Assets/Sound.wav

then it is used by the code below
      WCHAR *wideFilename = new WCHAR[strlen( filename ) + 1];
      MultiByteToWideChar( CP_ACP, 0, filename, -1, wideFilename, strlen( filename ) + 1 );
      wideFilename[strlen( filename )] = 0;

I'm hoping someone might know why this isn't working correctly.  THanks,
Watch Question
Top Expert 2012
This problem has been solved!
Unlock 2 Answers and 20 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE