Midas
Midas

Reputation: 7131

File as argument for Win32 application

How can I make a Win32 application open a file at startup when calling it like this (e.g. with a shortcut or via command line)?

program.exe "document.txt"

Upvotes: 1

Views: 442

Answers (2)

Random832
Random832

Reputation: 39000

If you have a Unicode program use lpCmdLine, otherwise use GetCommandLineW and pass the result to CommandLineToArgvW to get a list of strings for the arguments to the program, then it works just like with a command-line program.

Upvotes: 2

Ken Wayne VanderLinde
Ken Wayne VanderLinde

Reputation: 19349

This link shows how to retrieve command line arguments and turn them into an array of string

Even though it is written in a main, it works equally well in WinMain or any other function

Upvotes: 3

Related Questions