How does one create a custom App Extension?
Posted by BrushNo1806@reddit | learnprogramming | View on Reddit | 5 comments
Just like .ppt or .xlsx
How does one create a custom dot extension which Windows will recognise?
brinza888@reddit
First of all what are u talking about is “file extension”.
Answer for your question depends on what you mean by file extension. There are variants.
1) File extension as a part of file name. You can change file extension as you want without any damage to file content. Just will not be able to open by LMB click.
2) File association in OS, which tells OS which application call to open file with this file extension. Like open .docx in Word, open .xlsx in Excel. Can be changed in RMB context menu or straight in Windows Registry, where all associations are stored. But depends on OS.
3) File format to which file extension is tied. Like .docx tied to Microsoft Word document format. Developing new file format is not about choosing symbols after dot, but about internal content of file, its structure, and stored data. And requires some work of software engineers and architects.
BrushNo1806@reddit (OP)
Thanks a lot for the explaination!
I am talking about the file format here, I got curious about this when I tried to change the file format by remaning it (turned a .txt to .bat) and in me doing so, it changed the default way of opening the file. ( Like how a .txt opens in a notepad but a .bat file executes in cmd)
desrtfx@reddit
This only works because
.bat(and.cmd) files are text files (.txt).If you try that with any other file type, e.g. renaming a
.mp3to.aviyou will fail miserably.The file extension changes, but neither the file type, nor the file content.
The actual file type is usually (apart from plain text files) in the file header (the first x bytes of the file). If you e.g. look at a
.bmpfile (a Windows Bitmap Image) with a hex editor (or even in Notepad, but not recommendable) you will see the sequenceBMPin the first couple bytes. This is the file type identifier in the header.Other operating systems completely ignore the file extension and only look at the file header to determine the actual file type. There is where it gets more difficult to register custom file types.
Windows is the exception to the rule as it only looks at the file extension, which is part of the full file name. This is both a blessing and a curse, even more so since Windows by default hides the file extension for known file types. Malicious actors can abuse this by using seemingly safe file extensions (or using the hiding of extensions) to get you (the user) to execute malicious code.
desrtfx@reddit
This is far simpler than you think.
You create your extension - set it to whatever you want it to be and you only need to register it in Windows.
A simple google query: "Windows register custom file extension" brought the following as the first two links:
Any good installer program (NSIS, InnoSetup, and the install builders bundled with IDEs) can do that.
BrushNo1806@reddit (OP)
Thanks alot man!!