📄 subject_38094.htm
字号:
<p>
序号:38094 发表者:无量 发表日期:2003-04-30 16:47:57
<br>主题:在产生ICatRegister时,“STRSAFE_MAX_CCH常量,StringCchCopy函数”在哪个头文件里?
<br>内容:HRESULT CreateComponentCategory(CATID catid, WCHAR *catDescription)<BR>{<BR> ICatRegister *pcr = NULL ;<BR> HRESULT hr = S_OK ;<BR><BR> hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, <BR> NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);<BR> if (FAILED(hr))<BR> return hr;<BR><BR> // Make sure the HKCR\Component Categories\{..catid...}<BR> // key is registered.<BR> CATEGORYINFO catinfo;<BR> catinfo.catid = catid;<BR> catinfo.lcid = 0x0409 ; // english<BR> int len;<BR> // Make sure the provided description is not too long.<BR> // Only copy the first 127 characters if it is.<BR> // The second parameter of StringCchLength is the maximum<BR> // number of characters that may be read into catDescription.<BR> // There must be room for a NULL-terminator. The third parameter<BR> // contains the number of characters excluding the NULL-terminator.<BR> hr = StringCchLength(catDescription, STRSAFE_MAX_CCH, &len);<BR> if (SUCCEEDED(hr))<BR> {<BR> if (len>127)<BR> {<BR> len = 127;<BR> }<BR> } <BR> else<BR> {<BR> //TODO: Write an error handler;<BR> }<BR> // The second parameter of StringCchCopy is 128 because you need <BR> // room for a NULL-terminator. <BR> hr = StringCchCopy(catinfo.szDescription, len + 1, <BR> catDescription);<BR> // Make sure the description is null terminated.<BR> catinfo.szDescription[len + 1] = '\0';<BR><BR> hr = pcr->RegisterCategories(1, &catinfo);<BR> pcr->Release();<BR><BR> return hr;<BR>}<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:无量 回复日期:2003-04-30 16:55:40
<br>内容:编译时:<BR>error C2065: 'STRSAFE_MAX_CCH' : undeclared identifier<BR>error C2065: 'StringCchCopy' : undeclared identifier<BR><BR>已加了:<BR>#include "comcat.h"<BR>#include "OBJSAFE.H"
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:FirstHoward 回复日期:2003-04-30 20:26:53
<br>内容:Header strsafe.h <BR>Import library strsafe.lib <BR><BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Strings/StringReference/StringFunctions/stringcchcopy.asp
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:无量 回复日期:2003-05-06 23:34:10
<br>内容:strsafe.lib 和strsafe.h 在哪里?<BR>Visual Studio的目录中没有呀!<BR>邮给我好吗?<BR>liz_cq@163.com
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:无量 回复日期:2003-05-07 14:04:20
<br>内容:下载Windows core sdk后能解决。<BR>HRESULT CreateComponentCategory(CATID catid, WCHAR *catDescription)<BR>{<BR> ICatRegister *pcr = NULL ;<BR> HRESULT hr = S_OK ;<BR><BR> hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, <BR> NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);<BR> if (FAILED(hr))<BR> return hr;<BR><BR> // Make sure the HKCR\Component Categories\{..catid...}<BR> // key is registered.<BR> CATEGORYINFO catinfo;<BR> catinfo.catid = catid;<BR> catinfo.lcid = 0x0409 ; // english<BR> unsigned int len;<BR> // Make sure the provided description is not too long.<BR> // Only copy the first 127 characters if it is.<BR> // The second parameter of StringCchLength is the maximum<BR> // number of characters that may be read into catDescription.<BR> // There must be room for a NULL-terminator. The third parameter<BR> // contains the number of characters excluding the NULL-terminator.<BR> hr = StringCchLength((LPTSTR)catDescription, STRSAFE_MAX_CCH, &len);<BR> if (SUCCEEDED(hr))<BR> {<BR> if (len>127)<BR> {<BR> len = 127;<BR> }<BR> } <BR> else<BR> {<BR> //TODO: Write an error handler;<BR> }<BR> // The second parameter of StringCchCopy is 128 because you need <BR> // room for a NULL-terminator. <BR> hr = StringCchCopy((LPTSTR)catinfo.szDescription, len + 1, (LPTSTR)catDescription);<BR> // Make sure the description is null terminated.<BR> catinfo.szDescription[len + 1] = '\0';<BR><BR> hr = pcr->RegisterCategories(1, &catinfo);<BR> pcr->Release();<BR><BR> return hr;<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:无量 回复日期:2003-05-07 14:08:26
<br>内容:但是DllRegisterServer调用时,"CLSID_SafeItem"是什么,又在哪里定义的呢?<BR><BR>STDAPI DllRegisterServer(void)<BR>{<BR> AFX_MANAGE_STATE(_afxModuleAddrThis);<BR> HRESULT hr = S_OK ;<BR><BR> if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))<BR> return ResultFromScode(SELFREG_E_TYPELIB);<BR><BR> if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))<BR> return ResultFromScode(SELFREG_E_CLASS);<BR><BR> // Mark the control as safe for initializing.<BR> hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!");<BR> if (FAILED(hr))<BR> return hr;<BR> hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);<BR> if (FAILED(hr))<BR> return hr;<BR><BR> // Mark the control as safe for scripting.<BR> hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!");<BR> if (FAILED(hr))<BR> return hr;<BR> hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);<BR> if (FAILED(hr))<BR> return hr;<BR><BR> return NOERROR;<BR>}<BR><BR><BR><BR>error C2065: 'CLSID_SafeItem' : undeclared identifier<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -