⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_38094.htm

📁 vc
💻 HTM
字号:
<p>
序号:38094 发表者:无量 发表日期:2003-04-30 16:47:57
<br>主题:在产生ICatRegister时,“STRSAFE_MAX_CCH常量,StringCchCopy函数”在哪个头文件里?
<br>内容:HRESULT CreateComponentCategory(CATID catid, WCHAR *catDescription)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;ICatRegister *pcr = NULL ;<BR>&nbsp;&nbsp;&nbsp;&nbsp;HRESULT hr = S_OK ;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&amp;pcr);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Make sure the HKCR\Component Categories\{..catid...}<BR>&nbsp;&nbsp;&nbsp;&nbsp;// key is registered.<BR>&nbsp;&nbsp;&nbsp;&nbsp;CATEGORYINFO catinfo;<BR>&nbsp;&nbsp;&nbsp;&nbsp;catinfo.catid = catid;<BR>&nbsp;&nbsp;&nbsp;&nbsp;catinfo.lcid = 0x0409 ; // english<BR>&nbsp;&nbsp;&nbsp;&nbsp;int len;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Make sure the provided description is not too long.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Only copy the first 127 characters if it is.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// The second parameter of StringCchLength is the maximum<BR>&nbsp;&nbsp;&nbsp;&nbsp;// number of characters that may be read into catDescription.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// There must be room for a NULL-terminator. The third parameter<BR>&nbsp;&nbsp;&nbsp;&nbsp;// contains the number of characters excluding the NULL-terminator.<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = StringCchLength(catDescription, STRSAFE_MAX_CCH, &amp;len);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (SUCCEEDED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (len&gt;127)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; len = 127;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//TODO: Write an error handler;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;// The second parameter of StringCchCopy is 128 because you need <BR>&nbsp;&nbsp;&nbsp;&nbsp;// room for a NULL-terminator.&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = StringCchCopy(catinfo.szDescription, len + 1, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catDescription);<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Make sure the description is null terminated.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catinfo.szDescription[len + 1] = '\0';<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = pcr-&gt;RegisterCategories(1, &amp;catinfo);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pcr-&gt;Release();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;ICatRegister *pcr = NULL ;<BR>&nbsp;&nbsp;&nbsp;&nbsp;HRESULT hr = S_OK ;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&amp;pcr);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Make sure the HKCR\Component Categories\{..catid...}<BR>&nbsp;&nbsp;&nbsp;&nbsp;// key is registered.<BR>&nbsp;&nbsp;&nbsp;&nbsp;CATEGORYINFO catinfo;<BR>&nbsp;&nbsp;&nbsp;&nbsp;catinfo.catid = catid;<BR>&nbsp;&nbsp;&nbsp;&nbsp;catinfo.lcid = 0x0409 ; // english<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned int len;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Make sure the provided description is not too long.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Only copy the first 127 characters if it is.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// The second parameter of StringCchLength is the maximum<BR>&nbsp;&nbsp;&nbsp;&nbsp;// number of characters that may be read into catDescription.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// There must be room for a NULL-terminator. The third parameter<BR>&nbsp;&nbsp;&nbsp;&nbsp;// contains the number of characters excluding the NULL-terminator.<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = StringCchLength((LPTSTR)catDescription, STRSAFE_MAX_CCH, &amp;len);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (SUCCEEDED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (len&gt;127)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; len = 127;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//TODO: Write an error handler;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;// The second parameter of StringCchCopy is 128 because you need <BR>&nbsp;&nbsp;&nbsp;&nbsp;// room for a NULL-terminator.&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = StringCchCopy((LPTSTR)catinfo.szDescription, len + 1, (LPTSTR)catDescription);<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Make sure the description is null terminated.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catinfo.szDescription[len + 1] = '\0';<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = pcr-&gt;RegisterCategories(1, &amp;catinfo);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pcr-&gt;Release();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;AFX_MANAGE_STATE(_afxModuleAddrThis);<BR>&nbsp;&nbsp;&nbsp;&nbsp;HRESULT hr = S_OK ;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ResultFromScode(SELFREG_E_TYPELIB);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ResultFromScode(SELFREG_E_CLASS);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Mark the control as safe for initializing.<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!");<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Mark the control as safe for scripting.<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!");<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return hr;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;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 + -