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

  • SEARCH
  • Home
  • 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 7940827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:29:18+00:00 2026-06-03T23:29:18+00:00

I’m having some difficulties with the PathCombine function. It does not seem to work

  • 0

I’m having some difficulties with the PathCombine function. It does not seem to work correctly in conjunction with SHFileOperation(). My code is as follows:

    //beginning of method
    TCHAR* root = new TCHAR[MAX_PATH];
    root = L"C:\\Users\\jhow\\Desktop\\\0";

    //later on in the method
    TCHAR* t1Dir = new TCHAR[MAX_PATH]; //root
    TCHAR* t2Dir = new TCHAR[MAX_PATH]; //temp
    PathCombine(t1Dir,root,L"Folder1\\%REPLACE_THIS%\\\0");
    PathCombine(t2Dir,root,L"Folder1\\temp\0");

    sf.pFrom = t1Dir;
    //sf.pFrom = L"C:\\Users\\jhow\\Desktop\\Folder1\\%REPLACE_THIS%";
    sf.pTo = temporaryDir;

    //Copy files
    int n = SHFileOperation(&sf);

When I have it like it is above, the method sees sf.pTo, but for some reason it does not see sf.pFrom (even after playing around with different combinations of the \ and \0 at the end of the path name). n becomes 2, which I think means file not found… But for example, when I comment out.

    sf.pFrom = t1Dir;

and replace it with:

    sf.pFrom = L"C:\\Users\\jhow\\Desktop\\Folder1\\%REPLACE_THIS%";

SHFileOperation() works… it returns zero and I can see that all the files are copied into the directory. I find this odd seeing as they appear to be the same exact string (even when I debug and hover over the variables)… Anyone happen to know why this is happening? Is there something wrong with my syntax or logic? Because I don’t see it. I am using Visual Studio 2008. Thank you very much for your time.

  • 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-06-03T23:29:19+00:00Added an answer on June 3, 2026 at 11:29 pm

    You are allocating a buffer on the heap for your root variable, but then immediately pointing that variable to a read-only string literal instead, leaking the allocated buffer.

    More importantly, you are not taking into account that SHFileOperation() operates on double-null-terminated strings, but PathCombine() returns a single-null-terminated string instead. You are trying to include an extra null in your input to PathCombine(), but that will not work since PathCombine() take single-null-terminated strings as input, so it will never see your extra nulls. You ned to allocate enough space in your output buffers to hold the extra null terminators, and then make sure they are set to zeros before passing those buffers to SHFileOperation().

    Try this:

    LPTSTR root = TEXT("C:\\Users\\jhow\\Desktop\\"); 
    
    TCHAR t1Dir[MAX_PATH+2] = {0};
    TCHAR t2Dir[MAX_PATH+2] = {0};
    PathCombine(t1Dir, root, TEXT("Folder1\\%REPLACE_THIS%\\")); 
    PathCombine(t2Dir, root, TEXT("Folder1\\temp")); 
    
    sf.pFrom = t1Dir; 
    sf.pTo = t2Dir; 
    
    int n = SHFileOperation(&sf); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.