There is an overload of strcat_s that handles the sizeof() param if it's passed an array (but not a pointer) as the first param. So...
1 2
|
char path[256];
strcat_s(path,"\\");
|
should be fine.
What error are you getting? Are you hitting Unicode vs ANSI issues? If so, do what Chervil did and use the -A forms of function (GetModuleFileNameA, PathRemoveFileSpecA)
Or is something else going wrong?
But the right way to get the (current)
working directory is to use GetCurrentDirectory(), as shown by Chervil. Your function is returning the directory where the running executable is located, which is not always the working directory. If that's what you need, give your function another name as it doesn't behave the same way as the standard CRT getcwd() (sometimes _getcwd() with Microsoft CRT) and GetCurrentDirectory() and could lead to confusion.
And the WinSDK headers supply the define MAX_PATH for use when declaring buffers to hold paths (it's value is 260.) So you should use that instead.
char buf[MAX_PATH];
(You will also see _MAX_PATH being used, which is the corresponding define provided by the Microsoft CRT library. It has the same value.)
Andy