We can export ordinal using def file.But the system dlls doesn't use def files.Still shell32.dll have 569 ordinal exports and user32.dll have 181 ordinal exports.
Is there any way to export ordinal without def file?
Every exported function has an ordinal. The linker automatically numbers them, it starts at 1. But if you want to control the exact value (like Microsoft has to do with these DLLs) then you must use a .def file.
It is only required if client code used ordinals before, and you require binary compatibility with old code that doesn't get rebuilt, and you added or removed exported functions. To within 99.99% accuracy, client code never uses ordinals to link an exported function. They always use the name instead. You'd only have a dependency on the ordinal value if you exported the function with the NONAME attribute in the .def file, forcing the client code to use the ordinal instead. In practice, this is only ever done when you want to hide exports.
Microsoft can never make any assumptions about this and was forced to keep these DLLs binary compatible for the past 23 years. A burden that's not ours.