お世話になっております。
##作ろうとしていること
Visual Studio 2013 (MFC) で、Internet Explorer (IE11) で表示するHTMLへ埋め込む ActiveX コントロールを作成しています。HTMLのembedタグで呼びだされるもので、srcで指定したリソースの内容を読み取って、処理をします。
MSDNのサンプル MimeType を提示します。拡張子.mtpを"application/x-mimetype"といったContentType(MIME)とみなして、呼び出しを受けます。
サンプルでは、ocxをregsvr32などで登録されるとき、次のようなコードでレジストリにMIMETYPEを登録しています。
C++
1// MSDNのサンプル MimeType から抜粋 2STDAPI DllRegisterServer(void) 3{ 4 HKEY hkey = NULL; 5 HKEY hkey1 = NULL; 6 BOOL fErr = TRUE; 7 TCHAR szSubKey[513]; 8 9 // file extension for new mime type 10 LPCTSTR pszMTExt = _T(".mtp"); 11 // text for new mime content type 12 LPCTSTR pszMTContent = _T("application/x-mimetype"); 13 // text for mimetype subkey 14 LPCTSTR pszMTSubKey = _T("MIME\\DataBase\\Content Type\\application/x-mimetype"); 15 // extension named value 16 LPCTSTR pszMTExtVal = _T("Extension"); 17 // clsid 18 LPCTSTR pszMTCLSID = _T("{88888888-8888-8888-8888-000000000001}"); // この CLSID はテキトウ 19 // clsid named value name 20 LPCTSTR pszMTCLSIDVal = _T("CLSID"); 21 // content type named value name 22 LPCTSTR pszMTContentVal = _T("Content Type"); 23 // EnableFullPage key 24 LPCTSTR pszMTFullPage = _T("EnableFullPage"); 25 26 AFX_MANAGE_STATE(_afxModuleAddrThis); 27 28 if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid)) 29 return ResultFromScode(SELFREG_E_TYPELIB); 30 31 if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE)) 32 return ResultFromScode(SELFREG_E_CLASS); 33 34 do 35 { 36 // create new mime type key for our new mimetype. Only necessary for new mime types 37 if (ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, pszMTSubKey, &hkey)) 38 break; 39 40 // add extension value to that mime type key to associate .mtp files with the 41 // application/x-mimetype mime type 42 if (ERROR_SUCCESS != RegSetValueEx(hkey, pszMTExtVal, 0, REG_SZ, 43 (const BYTE *)pszMTExt, _tcslen(pszMTExt) * sizeof(TCHAR))) 44 break; 45 46 // Add class id to associate this object with the mime type 47 if (ERROR_SUCCESS != RegSetValueEx(hkey, pszMTCLSIDVal, 0, REG_SZ, 48 (const BYTE *)pszMTCLSID, _tcslen(pszMTCLSID) * sizeof(TCHAR))) 49 break; 50 51 RegCloseKey(hkey); 52 53 // Register .mtp as a file extension this is only necessary for new file extensions, addimg 54 // a new player for .avi files for instance would not require this 55 if (ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, pszMTExt, &hkey)) 56 break; 57 58 // Add content type to associate this extension with the content type. This is required 59 // and is used when the mime type is unknown and IE looks up associations by extension 60 if (ERROR_SUCCESS != RegSetValueEx(hkey, pszMTContentVal, 0, REG_SZ, 61 (const BYTE *)pszMTContent, _tcslen(pszMTContent) * sizeof(TCHAR))) 62 break; 63 64 RegCloseKey(hkey); 65 66 // Open the key under the control's clsid HKEY_CLASSES_ROOT\CLSID\<CLSID> 67 wsprintf(szSubKey, _T("%s\\%s"), pszMTCLSIDVal, pszMTCLSID); 68 if (ERROR_SUCCESS != RegOpenKey(HKEY_CLASSES_ROOT, szSubKey, &hkey)) 69 break; 70 71 // Create the EnableFullPage and extension key under this so that we can display files 72 // with the extension full frame in the browser 73 wsprintf(szSubKey, _T("%s\\%s"), pszMTFullPage, pszMTExt); 74 if (ERROR_SUCCESS != RegCreateKey(hkey, szSubKey, &hkey1)) 75 break; 76 77 fErr = FALSE; 78 } while (FALSE); 79 80 if (hkey) 81 RegCloseKey(hkey); 82 83 if (hkey1) 84 RegCloseKey(hkey1); 85 86 if (fErr) 87 MessageBox(0, _T("Cannot register player for mime type"), _T("Registration Error"), MB_OK); 88 89 return NOERROR;
##疑問
サンプルを作成・登録し、次のようなHTML文をIE11に読み込ませました。すると、embedタグのうち、上2つは呼ばれます※が、下1つは呼ばれません。
※コントロールのDoPropExchangeメソッドが呼ばれ、PX_String(pPX, _T("Src"), m_Src);ではm_Srcにembedタグで指定したsrc属性の文字列が入ります。
HTML
1<!DOCTYPE html> 2<html> 3<head> 4</head> 5<body> 6<p>welcome to custom activex!</p> 7<!-- GOOD! 8<object id="myactivex" classid="clsid:88888888-8888-8888-8888-000000000001" width=200 height=300> 9<param name="src" value="ABC"> 10</object> 11--> 12 13<embed src="file://C:/sample.mtp" width=400 height=200> 14 15<embed src="http://www.example.com/sample.mtp" width=400 height=200 type="application/x-mimetype"> 16 17<embed src="http://www.example.com/sample.mtp" width=400 height=200> 18 19</body> 20</html>
fileスキームであるか(拡張子で判断)、httpスキームであってもtype属性でMIMEを指定すれば呼び出されます。
しかし、httpスキームでtype指定しないとなぜか呼ばれません。
##知りたいこと
embedタグへ src="http://www.example.com/sample.mtp" など、type指定せずとも拡張子.mtpを解釈しさせてActiveXを呼ばせたいです。fileスキームのときは、拡張子をみて自動判断しているようなのですが。もっとレジストリ登録が必要なのでしょうか?
このあたりの情報をご存知の方、ご教示いただけますと幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。