C++ Question Absolute Paths

Max-Q

99 40
Addon Developer
Joined
Jul 5, 2021
Messages
489
Reaction score
684
Points
108
Location
Cislunar Space
Website
www.orbiter-forum.com
So I am working on a project and need to use the ShellExecute() function to open a file (PDF) from inside my vessel’s code. It works just fine if I use an absolute path to the file, but that means it will only work in my orbiter install. The file is located in orbiter‘s Docs subfolder. I was wondering if there is any way to find the absolute path to the orbiter installation’s root directory when my vessel is loaded and dump it to a char* variable. To be clear, I am not trying to get orbiter to open the PDF, I want it to open in whatever application the user has set up to view PDFs by default.

Any help is appreciated,
Max-Q
 

Max-Q

99 40
Addon Developer
Joined
Jul 5, 2021
Messages
489
Reaction score
684
Points
108
Location
Cislunar Space
Website
www.orbiter-forum.com

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,996
Reaction score
1,676
Points
203
Location
Langendernbach
Is there a document that describes the Windows C++ API like the orbiter one is documented? Sorry for the maybe dumb question, I am totally lost at C++ outside of the orbiter API.

No longer, the Microsoft homepages are now the prime reference. For general C or C++ functions, I can recommend you


While this doesn't help you with your question above, its a really good resource for looking up useful tools and examples in the standard library.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,388
Reaction score
1,634
Points
203
Location
between the planets
Orbiter actually has an api function for opening files with a relative path:

C++:
OAPIFUNC FILEHANDLE oapiOpenFile  ( const char *  fname, 
  FileAccessMode  mode, 
  PathRoot  root = ROOT 
 )

From the documentation:
Orbiter API: File IO Functions The file path defined in fname is relative to either the main Orbiter folder or to one of Orbiter's default subfolders, depending on the root parameter:
  • ROOT Orbiter main directory
  • CONFIG Orbiter config folder
  • SCENARIOS Orbiter scenarios folder
  • TEXTURES Orbiter standard texture folder
  • TEXTURES2 Orbiter high-res texture folder
  • MESHES Orbiter mesh folder
  • MODULES Orbiter module folder
 

Max-Q

99 40
Addon Developer
Joined
Jul 5, 2021
Messages
489
Reaction score
684
Points
108
Location
Cislunar Space
Website
www.orbiter-forum.com
I got it working. Here is the code, oapiOpenFile() won't work for me since I am actually trying to open a PDF in acrobat reader.
C++:
void MyProject::OpenFlightManual()
{
    char orbiter_root[1024] = "";
    char path[1024] = "\\Doc\\MyProject\\MyFile.pdf";
    char full_path[2048] = "";
    GetCurrentDirectory(1024, orbiter_root);
    strcpy(full_path, orbiter_root);
    strcat(full_path, path);
    ShellExecute(NULL, "open", full_path, NULL, NULL, SW_SHOW);
}
Thanks for the help!
 
Top