2

How do I concatenate (or even assign) two strings (TCHAR arrays, I guess) in MinGW with GCC?

  • StrCatBuff?
    #include <shlwapi.h> and -lshlwapi do work, but you're not supposed to use it
  • _tcscat?
    Seems not to exist
  • StringCchCat
    Seems not to exist. strsafe.h doesn't exist.

The same holds true for their respective assignment functions like StringCchCpy and _tcscpy.

AndreKR
  • 32,613
  • 18
  • 106
  • 168

1 Answers1

2

_tcscat (or the "secure" version, _tcscat_s) works just fine for concatenating arrays of TCHARs. You have to include tchar.h in order to use either of these functions.

The same should be true for StringCchCat, which as you mention is defined in strsafe.h.

If you're missing these header files, make sure that you've installed the Windows SDK. It's probably not included by default with MinGW like it is with Microsoft's tooling.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Allright, I just installed half a GB just for some string functions. Now, how do I make MinGW aware of it? – AndreKR Feb 08 '12 at 03:48
  • @AndreKR: No idea. That information should be in the documentation for your development tools. Or perhaps can be found in the answers to [this question](http://stackoverflow.com/questions/1549123/how-to-use-the-windows-api-in-mingw). – Cody Gray - on strike Feb 08 '12 at 03:50
  • It's even worse. My program doesn't compile any longer: `C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to WinMain@16` – AndreKR Feb 08 '12 at 03:52
  • 1
    @AndreKR: `WinMain` is not the correct name for the entry point in Unicode builds. The function is named `wWinMain` in that case. You can also use the `_tWinMain` macro (defined in `tchar.h`) to automatically choose the correct entry point name. Make sure that the `lpCmdLine` parameter is defined as type `LPTSTR` so that it matches the definition of the function in the headers. – Cody Gray - on strike Feb 08 '12 at 03:57
  • 1
    Hm, somehow it compiles again. Using wWinMain didn't work, probably because of http://stackoverflow.com/questions/3571250/wwinmain-unicode-and-mingw. As for strsafe.h, it still doesn't find it. – AndreKR Feb 08 '12 at 05:21
  • @AndreKR: Strange. Sounds like MinGW is completely broken. This is only one of the many reasons I don't use it. I'd give up and download Visual Studio Express instead. – Cody Gray - on strike Feb 08 '12 at 05:26
  • I did. Continuation at http://stackoverflow.com/questions/9198787/how-do-i-compile-a-window-api-program-using-cl ;) – AndreKR Feb 08 '12 at 17:55