-1

Question, how do I add a GetCurrentDirectory file? I have this code:

const unsigned long maxDir = 260;
         char currentDir [maxDir] = "";
         GetCurrentDirectory (maxDir, currentDir);
std :: cout << currentDir << std :: endl;

ok but if I want to add a file std :: cout << currentDir + "mydll.dll" << std :: endl;

it gives me an error.

How can I include the current directory + the file?

It is to inject a dll.

LPCSTR DllPath = currentDir + "mydll.dll";

Thank you so much.

solution: You must use strcpy() and strcat() for C-style strings. Alternatively, you can use std::string, which would allow you to use the + operator in the way that you intended

Thanks a lot: Andreas Wenzel

Santy
  • 1
  • 2
  • What is the error? – selbie Feb 09 '20 at 20:36
  • 1
    The line `LPCSTR DllPath = currentDir + "mydll.dll;` will not work, because those are C-style strings. You must use [`strcpy()`](https://en.cppreference.com/w/c/string/byte/strcpy) and [`strcat()`](https://en.cppreference.com/w/c/string/byte/strcat) for C-style strings. Alternatively, you can use [std::string](https://en.cppreference.com/w/cpp/string/basic_string), which would allow you to use the + operator in the way that you intended. – Andreas Wenzel Feb 09 '20 at 20:36
  • If you want to get the directory that a program is running from? If so, I suggest you could try to use [GetModuleFileNameA function](https://learn.microsoft.com/zh-cn/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea?redirectedfrom=MSDN) I suggest you could refer to to the link:https://stackoverflow.com/questions/875249/how-to-get-current-directory – Jeaninez - MSFT Feb 12 '20 at 08:56

1 Answers1

0

I think you are missing by the actual path. You should do like below(if it is a Linux) "CurrentDir/FileName" std :: cout << currentDir + "\" + "mydll.dll" << std :: endl;

Gokulnath
  • 23
  • 1
  • 8
  • Good afternoon friend, it's windows, and it doesn't keep throwing error. https://ibb.co/09kfJCK – Santy Feb 09 '20 at 20:34
  • The expression `currentDir + "\" + "mydll.dll"` does not work with C-style strings. Also, the backslash character must be escaped in a string literal. – Andreas Wenzel Feb 09 '20 at 20:41