c++stringwindows-celpcstr

C++ concat LPCTSTR


I am implementing a custom action for a WindowsCE CAB file, and I need to concat a LPCTSTR to get a proper path to an exe.

My custom action receives a LPCTSTR as an argument.

So (pseudocode):

extern "C" codeINSTALL_EXIT MYCUSTOMACTION_API Install_Exit(
    HWND    hwndParent,
    LPCTSTR pszInstallDir,
    WORD    cFailedDirs,
    WORD    cFailedFiles,
    WORD    cFailedRegKeys,
    WORD    cFailedRegVals,
    WORD    cFailedShortcuts
)
{
    if (FALSE == LaunchApp(pszInstallDir + "\\MyApp.exe"))
       ::MessageBox(hwndParent, L"Could not launch app!", L"Setup", MB_ICONINFORMATION );
    return codeINSTALL_EXIT_DONE;
}

This is using the imaginary "+" operator, that I would use in my standard language, C#.

I have relatively little experience in C++. What is the proper way to append a LPCTSTR for my purposes? The LaunchApp method uses this type as an argument.

Also if I want to display the resulting path (for debugging purposes) in a MessageBox, is there a quick way to convert to a LPCWSTR?


Solution

  • For concatenation use StringCchCat

    TCHAR pszDest[260] = _T("");
    StringCchCat(pszDest, 260, pszInstallDir); 
    StringCchCat(pszDest, 260, _T("\\MyApp.exe"));
    LaunchApp(pszDest);