-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmime.cpp
46 lines (36 loc) · 1.05 KB
/
mime.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <Windows.h>
#include <string>
#include<fstream>
using namespace std;
string GetMimeType(const string &szExtension)
{
HKEY hKey = NULL;
string size = "application/unknown";
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, szExtension.c_str(),
0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
char szBuffer[256] = {0};
DWORD dwBuffSize = sizeof(szBuffer);
if (RegQueryValueEx(hKey, "Content Type", NULL, NULL,
(LPBYTE)szBuffer, &dwBuffSize) == ERROR_SUCCESS)
{
size = szBuffer;
}
RegCloseKey(hKey);
}
return size;
}
int main()
{
std::ofstream myfile;
myfile.open ("example.txt");
myfile << "Welcome\n";
myfile.close();
string szExt1 = ".pdf";
string szExt2 = ".txt";
string szMime1 = GetMimeType(szExt1);
string szMime2 = GetMimeType(szExt2);
printf("%s = %s\n%s = %s\n", szExt1.c_str(), szMime1.c_str(),
szExt2.c_str(), szMime2.c_str());
return 0;
}