Send TEMP Path To argv - Need Assistance Please

Good morning everyone,

I have the following:

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdlib.h>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	wchar_t* argv[] = { L"program.exe", L"%TEMP%\NewDir" };
	wmain2(2,argv);
	return 0;
}


I read the msdn article for GetTempPath but I don't quite understand.

Any help would be very appreciated.

Thanks!
GetTempPath return the path - it works like this:
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdlib.h>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
  char buffer[256] = { 0 };

  GetTempPathA(sizeof(buffer), buffer);
  MessageBoxA(0, buffer, "Temp Path", MB_OK);

  return 0;
}


What do you want to do ?
Thanks for the quick reply!

In line #9 of my original post, I need to put the TEMP path where it says L"%TEMP%...".

That will be sent to argv[2] in wmain2.

I am still in need of help. I still don't really understand how to implement GetTempPath() into my code.
Last edited on
You could do it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdlib.h>
#include <string>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
  std::wstring buffer(512, ' ');

  DWORD len = GetTempPathW(buffer.size(), &buffer[0]);
  buffer.resize(len);
  buffer += L"\\NewDir";
  MessageBoxW(0, buffer.c_str(), L"Temp Path", MB_OK);

  return 0;
}


What is wmain2 ?
Thomas1965,

Let me clarify: wmain2 is my "main()" function of my code (which I did not copy here). If I compile my code using that section as my entry point, my code will use the command prompt. I want this as a Windows program (int WINAPI WinMain()" so that it does not display the command prompt window.

I just need to send the argv, argc information to the wmain2 function via WINAPI WinMain().

So, in the code I posted in the original post, if I changed line #9 to read:

wchar_t* argv[] = { L"program.exe", L"C:\Folder" };

It execute properly using "C;\Folder". But, I need to identify the Temp folder of the machine the program is running on instead of "C:\Folder".
Easiest would be using a vector to pass the arguments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdlib.h>
#include <string>
#include <windows.h>
#include <vector>

using namespace std;


void wmain2(vector<wstring> &args)
{
  // args[0] = Program name 
  // args[1] = Temp folder 
  wstring msg = args[0] + L"\r\n" + args[1];
  MessageBoxW(0, msg.c_str(), L"Params", MB_OK);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
  std::wstring buffer(512, ' ');

  DWORD len = GetTempPathW(buffer.size(), &buffer[0]);
  buffer.resize(len);
  buffer += L"\\NewDir";
  vector<wstring> args = { L"Program.exe", buffer };
  wmain2(args);

  return 0;
}
Topic archived. No new replies allowed.