文武人尹
www.bin.idv.tw
2013年5月12日星期日
2013年5月7日星期二
PostgreSQL現存表中加入流水號主鍵
1. CREATE SEQUENCE test_sid_seq;
2. ALTER TABLE test ADD sid INT UNIQUE;
3. ALTER TABLE test ALTER COLUMN sid SET DEFAULT NEXTVAL('test_sid_seq');
4. UPDATE test SET sid = NEXTVAL('test_sid_seq');
5. ALTER TABLE test ADD PRIMARY KEY (sid);
2013年5月2日星期四
javascript判斷XP與windows 7
var OSName="Unknown OS";
var OS = navigator.appVersion;
if (OS.indexOf("Win") != -1){
if ((OS.indexOf("Windows NT 5.1") != -1) || (OS.indexOf("Windows XP") != -1))
OSName = "Win XP";
}else if ((OS.indexOf("Windows NT 7.0") != -1) || (OS.indexOf("Windows NT 6.1") != -1)) {
OSName = "Win 7";
}
}
alert(OSName);
2013年4月24日星期三
將 MFC ActiveX 控制項標示為安全的方式
- 下列的 cathelp.h 和 cathelp.cpp 檔案加入至專案,以實作 CreateComponentCategory 和 RegisterCLSIDInCategory 的 helper 函式。
Cathelp.h
#include "comcat.h" // Helper function to create a component category and associated // description HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription); // Helper function to register a CLSID as belonging to a component // category HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);Cathelp.cpp
#include "comcat.h" // Helper function to create a component category and associated // description HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription) { ICatRegister* pcr = NULL ; HRESULT hr = S_OK ; hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); if (FAILED(hr)) return hr; // Make sure the HKCR\Component Categories\{..catid...} // key is registered CATEGORYINFO catinfo; catinfo.catid = catid; catinfo.lcid = 0x0409 ; // english // Make sure the provided description is not too long. // Only copy the first 127 characters if it is int len = wcslen(catDescription); if (len>127) len = 127; wcsncpy(catinfo.szDescription, catDescription, len); // Make sure the description is null terminated catinfo.szDescription[len] = '\0'; hr = pcr->RegisterCategories(1, &catinfo); pcr->Release(); return hr; } // Helper function to register a CLSID as belonging to a component // category HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid) { // Register your component categories information. ICatRegister* pcr = NULL ; HRESULT hr = S_OK ; hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); if (SUCCEEDED(hr)) { // Register this category as being "implemented" by // the class. CATID rgcatid[1] ; rgcatid[0] = catid; hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid); } if (pcr != NULL) pcr->Release(); return hr; } - 修改 DllRegisterServer,以標記為安全的控制項。在.cpp 檔在專案中,找出 DllRegisterServer 的實作。您必須將數個項目加入至這個.cpp 檔案。包括實作 CreateComponentCategory 和 RegisterCLSIDInCategory 的檔案:定義安全的元件類別相關聯的 GUID:
#include "CatHelp.h"定義您的控制項相關聯的 GUID。為了簡單起見,您可以向他人借IMPLEMENT_OLECREATE_EX巨集儲存在控制項的主要.cpp 檔中的 GUID。稍微調整格式,使它看起來如下所示:
const CATID CATID_SafeForScripting = {0x7dd95801,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}}; const CATID CATID_SafeForInitializing = {0x7dd95802,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};要將您的控制項為這兩種安全進行指令碼處理與初始化,可修改的 DllRegisterServer 函式如下所示:
const GUID CDECL BASED_CODE _ctlid = { 0x43bd9e45, 0x328f, 0x11d0, { 0xa6, 0xb9, 0x0, 0xaa, 0x0, 0xa7, 0xf, 0xc2 } };
STDAPI DllRegisterServer(void) { AFX_MANAGE_STATE(_afxModuleAddrThis); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid)) return ResultFromScode(SELFREG_E_TYPELIB); if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE)) return ResultFromScode(SELFREG_E_CLASS); if (FAILED( CreateComponentCategory( CATID_SafeForScripting, L"Controls that are safely scriptable") )) return ResultFromScode(SELFREG_E_CLASS); if (FAILED( CreateComponentCategory( CATID_SafeForInitializing, L"Controls safely initializable from persistent data") )) return ResultFromScode(SELFREG_E_CLASS); if (FAILED( RegisterCLSIDInCategory( _ctlid, CATID_SafeForScripting) )) return ResultFromScode(SELFREG_E_CLASS); if (FAILED( RegisterCLSIDInCategory( _ctlid, CATID_SafeForInitializing) )) return ResultFromScode(SELFREG_E_CLASS); return NOERROR; }
- 您可以不要移除元件類別目錄,因為其他控制項可能正在使用它。
- 雖然有未定義的 UnRegisterCLSIDInCategory 函式,根據預設值 DllUnregisterServer 控制項的項目從登錄中移除完全。因此,控制項的登錄中移除類別實在沒什麼用處。
HKEY_CLASSES_ROOT\Component
Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}
HKEY_CLASSES_ROOT\Component
Categories\{7DD95802-9882-11CF-9FA9-00AA006C42C4}
HKEY_CLASSES_ROOT\CLSID\{"your controls GUID"}\Implemented
Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}
HKEY_CLASSES_ROOT\CLSID\{"your controls GUID"}\Implemented
Categories\{7DD95802-9882-11CF-9FA9-00AA006C42C4}
2013年4月23日星期二
建立Hisecure API認證IC卡(工商、自然人)讀取憑證資訊activeX元件步驟
1. 至內政部憑證管理中心申請Hisecure API帳號(目前可透過工商憑證線上申請),審核時間約一周。
2. 通過後至Hisecure下載API及範例程式
3. HiSecure_7.0.4_GPKI內的example有TestHiSecure VS專案(for exe)可供參考
4. 建立一VC++ MFC ActiveX控制項專案,
a.專案屬性 => 組態屬性 => 一般 => 組態型別:動態程式庫(.dll)
b.專案屬性 => 組態屬性 => C++ => 一般 => 其他Include目錄:../include(參考TestHiSecure專案將include目錄複製到新建專案)
c.專案屬性 => 組態屬性 => 連結器 => 一般 => 其他程式庫目錄:../lib/Win32_static(參考TestHiSecure專案將lib目錄複製到新建專案)
d.專案屬性 => 組態屬性 => 連結器 => 輸入 => 其他相依性:HiSecure.lib libeay32.lib pkcs11lib.lib ws2_32.lib(參考TestHiSecure專案)
e.專案屬性 => 組態屬性 => 連結器 => 輸入 => 忽略特定程式庫:LIBCMT.lib
5. 建置專案產生xxx.lib及xxx.ocx檔
6. 至內政部憑證管理中心下載HiCOS,因為Hisecure API實際是透過HiCOS dll元件來讀取憑證,安裝HiCOS後,在系統目錄(如 C:\WINDOWS\system32)中取得BfiveUcs.dll、chtp15v2.dll ICCDFCDLL.dll、selectcardv2.dll、starp15v2.dll UCSBFive.dll、HiCOSCSPv32.dll、HiCOSCSPv32.sig、HiCOSPKCS11.dll元件
7. 建立install.inf,內容如:
[version]
signature=$Chicago$
AdvancedINF=2.0
[Add.Code]
HiCOSCSPv32.dll=HiCOSCSPv32.dll
HiCOSCSPv32.sig=HiCOSCSPv32.sig
HiCOSPKCS11.dll=HiCOSPKCS11.dll
chtp15v2.dll=chtp15v2.dll
ICCDFCDLL.dll=ICCDFCDLL.dll
UCSBFive.dll=UCSBFive.dll
starp15v2.dll=starp15v2.dll
selectcardv2.dll=selectcardv2.dll
chtp15v2.dll=chtp15v2.dll
BfiveUcs.dll=BfiveUcs.dll
hicosTest.ocx=hicosTest.ocx
hicosTest.lib=hicosTest.lib
[hicosTest.ocx]
file-win32-x86=thiscab
RegisterServer=yes
clsid={6D33DDDD-F3DC-4608-B81C-0D17C61200AD}
FileVersion=1,0,0,1
DestDir=11
[hicosTest.lib]
file-win32-x86=thiscab
DestDir=11
[HiCOSPKCS11.dll]
file-win32-x86=thiscab
DestDir=11
[HiCOSCSPv32.sig]
file-win32-x86=thiscab
DestDir=11
[HiCOSCSPv32.dll]
file-win32-x86=thiscab
DestDir=11
[BfiveUcs.dll]
file-win32-x86=thiscab
DestDir=11
[chtp15v2.dll]
file-win32-x86=thiscab
DestDir=11
[selectcardv2.dll]
file-win32-x86=thiscab
DestDir=11
[starp15v2.dll]
file-win32-x86=thiscab
DestDir=11
[UCSBFive.dll]
file-win32-x86=thiscab
DestDir=11
[chtp15v2.dll]
file-win32-x86=thiscab
DestDir=11
[ICCDFCDLL.dll]
file-win32-x86=thiscab
DestDir=11
[RegisterFiles]
%11%/hicosTest.ocx
8. 透過cabsdk建立cab,產生cab語法如:CABARC -s 6144 n xxx.cab install.inf BfiveUcs.dll chtp15v2.dll ICCDFCDLL.dll selectcardv2.dll starp15v2.dll UCSBFive.dll HiCOSCSPv32.dll HiCOSCSPv32.sig HiCOSPKCS11.dll hicosTest.lib hicosTest.ocx
9. 在網頁中emebed元件,並將網頁及cab檔放在網站伺服器中便可使用
html:
< object id="hicosTestCtrl" style="DISPLAY: none; LEFT: 0px; TOP: 0px" classid="clsid:6D33DDDD-F3DC-4608-B81C-0D17C61200AD" CODEBASE="xxx.cab#version=1,0,0,1" >< /object >
javascript:
var r = hicosTestCtrl.checkLogin10(document.frm.pin.value);
p.s. 將 MFC ActiveX 控制項標示為安全的方式
2. 通過後至Hisecure下載API及範例程式
3. HiSecure_7.0.4_GPKI內的example有TestHiSecure VS專案(for exe)可供參考
4. 建立一VC++ MFC ActiveX控制項專案,
a.專案屬性 => 組態屬性 => 一般 => 組態型別:動態程式庫(.dll)
b.專案屬性 => 組態屬性 => C++ => 一般 => 其他Include目錄:../include(參考TestHiSecure專案將include目錄複製到新建專案)
c.專案屬性 => 組態屬性 => 連結器 => 一般 => 其他程式庫目錄:../lib/Win32_static(參考TestHiSecure專案將lib目錄複製到新建專案)
d.專案屬性 => 組態屬性 => 連結器 => 輸入 => 其他相依性:HiSecure.lib libeay32.lib pkcs11lib.lib ws2_32.lib(參考TestHiSecure專案)
e.專案屬性 => 組態屬性 => 連結器 => 輸入 => 忽略特定程式庫:LIBCMT.lib
5. 建置專案產生xxx.lib及xxx.ocx檔
6. 至內政部憑證管理中心下載HiCOS,因為Hisecure API實際是透過HiCOS dll元件來讀取憑證,安裝HiCOS後,在系統目錄(如 C:\WINDOWS\system32)中取得BfiveUcs.dll、chtp15v2.dll ICCDFCDLL.dll、selectcardv2.dll、starp15v2.dll UCSBFive.dll、HiCOSCSPv32.dll、HiCOSCSPv32.sig、HiCOSPKCS11.dll元件
7. 建立install.inf,內容如:
[version]
signature=$Chicago$
AdvancedINF=2.0
[Add.Code]
HiCOSCSPv32.dll=HiCOSCSPv32.dll
HiCOSCSPv32.sig=HiCOSCSPv32.sig
HiCOSPKCS11.dll=HiCOSPKCS11.dll
chtp15v2.dll=chtp15v2.dll
ICCDFCDLL.dll=ICCDFCDLL.dll
UCSBFive.dll=UCSBFive.dll
starp15v2.dll=starp15v2.dll
selectcardv2.dll=selectcardv2.dll
chtp15v2.dll=chtp15v2.dll
BfiveUcs.dll=BfiveUcs.dll
hicosTest.ocx=hicosTest.ocx
hicosTest.lib=hicosTest.lib
[hicosTest.ocx]
file-win32-x86=thiscab
RegisterServer=yes
clsid={6D33DDDD-F3DC-4608-B81C-0D17C61200AD}
FileVersion=1,0,0,1
DestDir=11
[hicosTest.lib]
file-win32-x86=thiscab
DestDir=11
[HiCOSPKCS11.dll]
file-win32-x86=thiscab
DestDir=11
[HiCOSCSPv32.sig]
file-win32-x86=thiscab
DestDir=11
[HiCOSCSPv32.dll]
file-win32-x86=thiscab
DestDir=11
[BfiveUcs.dll]
file-win32-x86=thiscab
DestDir=11
[chtp15v2.dll]
file-win32-x86=thiscab
DestDir=11
[selectcardv2.dll]
file-win32-x86=thiscab
DestDir=11
[starp15v2.dll]
file-win32-x86=thiscab
DestDir=11
[UCSBFive.dll]
file-win32-x86=thiscab
DestDir=11
[chtp15v2.dll]
file-win32-x86=thiscab
DestDir=11
[ICCDFCDLL.dll]
file-win32-x86=thiscab
DestDir=11
[RegisterFiles]
%11%/hicosTest.ocx
8. 透過cabsdk建立cab,產生cab語法如:CABARC -s 6144 n xxx.cab install.inf BfiveUcs.dll chtp15v2.dll ICCDFCDLL.dll selectcardv2.dll starp15v2.dll UCSBFive.dll HiCOSCSPv32.dll HiCOSCSPv32.sig HiCOSPKCS11.dll hicosTest.lib hicosTest.ocx
9. 在網頁中emebed元件,並將網頁及cab檔放在網站伺服器中便可使用
html:
< object id="hicosTestCtrl" style="DISPLAY: none; LEFT: 0px; TOP: 0px" classid="clsid:6D33DDDD-F3DC-4608-B81C-0D17C61200AD" CODEBASE="xxx.cab#version=1,0,0,1" >< /object >
javascript:
var r = hicosTestCtrl.checkLogin10(document.frm.pin.value);
p.s. 將 MFC ActiveX 控制項標示為安全的方式
訂閱:
文章 (Atom)