📄 subject_63049.htm
字号:
<p>
序号:63049 发表者:风儿 发表日期:2003-12-01 11:06:29
<br>主题:请问怎样才能在COM(dll)中定义的enum类型,能在被调程序中使用?请看例子:
<br>内容:在COM(MyType.dll)中定义有(怎么个定义法我不清楚):<BR>enum MYTypes<BR>{<BR> P_TYPE1 = 0,<BR> P_TYPE2 = 1,<BR> P_TYPE3 = 2,<BR> P_TYPE4 = 3,<BR> P_TYPE5 = 4,<BR> TYPE6 = 5<BR>};<BR>程序调用时如下:<BR>ITypeManangerPtr pTypeMgr(__uuidof(TypeMananger));<BR><BR>pTypeMgr.GeFaceItObject(P_TYPE1, &pVerify);//P_TYPE1直接使用,并没有在程序中重定义。<BR><BR>问怎样在COM(dll)中定义MYTypes后能在被调程序中使用?<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:zhangquan 回复日期:2003-12-01 11:17:19
<br>内容:.在工程名.idl文件的开头:<BR>typedef enum PinnacleTypes<BR>{<BR> P_UNDEFINED = 0,<BR> P_SURVEILLANCE = 1,<BR> P_VERIFICATION = 2,<BR> P_WEB_QUERY = 3,<BR> P_VIDEO_CAPTURE = 4,<BR> PRODUCT_COUNT = 5<BR>} _cyl;<BR><BR>在方法中可以这样定义:fangfa([in]_cyl zhqu)<BR><BR>被调程序使用该也可以定义这个结构,或者把工程名.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>
回复者:风儿 回复日期:2003-12-01 11:32:24
<br>内容:zhqu,谢谢你的答案。你的这种方法是对的。但是我发现在调用它的程序编译后,你这种方法与我看到的另一种有些不一样。请看下面:<BR><BR>这个是现在的一个Pinnacle.dll的pinnacle.tlh文件的部份内容。<BR><BR>struct /* coclass */ LicenseManager;<BR>struct __declspec(uuid("01db4f7c-b2e8-4994-bc7f-7f3301e38579"))<BR>/* dual interface */ ILicenseManager;<BR><BR>//<BR>// Smart pointer typedef declarations<BR>//<BR><BR>_COM_SMARTPTR_TYPEDEF(ILicenseManager, __uuidof(ILicenseManager));<BR><BR>//<BR>// Type library items<BR>//<BR><BR>enum PinnacleTypes<BR>{<BR> P_UNDEFINED = 0,<BR> P_SURVEILLANCE = 1,<BR> P_VERIFICATION = 2,<BR> P_WEB_QUERY = 3,<BR> P_VIDEO_CAPTURE = 4,<BR> PRODUCT_COUNT = 5<BR>};<BR><BR><BR>下面这个是我刚才照你所说的方法生成的tlh文件的部份内容:<BR>_COM_SMARTPTR_TYPEDEF(ISetReg, __uuidof(ISetReg));<BR>_COM_SMARTPTR_TYPEDEF(ISetLicense, __uuidof(ISetLicense));<BR><BR>//<BR>// Type library items<BR>//<BR><BR>struct __declspec(uuid("fc256600-2623-42f5-a760-04f079eae525"))<BR>SetReg;<BR> // [ default ] interface ISetReg<BR><BR>struct __declspec(uuid("7d8e9c43-83da-49ec-9cc5-793d45d17c35"))<BR>ISetReg : IDispatch<BR>{<BR> //<BR> // Wrapper methods for error-handling<BR> //<BR><BR> HRESULT GetRegcom (<BR> BSTR * bstrVal );<BR> HRESULT fangfa (<BR> enum PinnacleTypes zhqu );<BR><BR> //<BR> // Raw methods provided by interface<BR> //<BR><BR> virtual HRESULT __stdcall raw_GetRegcom (<BR> BSTR * bstrVal ) = 0;<BR> virtual HRESULT __stdcall raw_fangfa (<BR> enum PinnacleTypes zhqu ) = 0;<BR>};<BR><BR>enum PinnacleTypes<BR>{<BR> P_UNDEFINED = 0,<BR> P_SURVEILLANCE = 1,<BR> P_VERIFICATION = 2,<BR> P_WEB_QUERY = 3,<BR> P_VIDEO_CAPTURE = 4,<BR> PRODUCT_COUNT = 5<BR>};<BR><BR>看到区别了吗?<BR>我发现很多的都是在“// Type library items”行下面就是所定议的东西了。而照你的方法定义的不在这个地方。也许在使用上没有什么区别,可是我还是有点好奇,想知道那种的是怎么个定义法。<BR><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>
回复者:勇敢的心72 回复日期:2003-12-01 21:46:44
<br>内容:How To Implement Enumerated Properties in ATL <BR><BR>Q181255<BR><BR><BR>--------------------------------------------------------------------------------<BR>The information in this article applies to:<BR><BR>The Microsoft Active Template Library (ATL), versions 2.1, 3.0, used with:<BR>Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0 <BR>Microsoft Visual C++, 32-bit Professional Edition, version 5.0 <BR>Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0 <BR>Microsoft Visual C++, 32-bit Professional Edition, version 6.0 <BR>Microsoft Visual C++, 32-bit Learning Edition, version 6.0<BR><BR>--------------------------------------------------------------------------------<BR><BR><BR>SUMMARY<BR>The Atlenum sample shows how to implement enumerated properties in ATL. <BR><BR><BR><BR>MORE INFORMATION<BR>The following files are available for download from the Microsoft Download Center:<BR><BR><BR>Atlenum.exe<BR><BR>For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base: <BR><BR>Q119591 How to Obtain Microsoft Support Files from Online Services <BR>Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file. <BR><BR><BR><BR>Enumerated properties have a predefined set of possible values that you can assign to them. For example, when you define an enumerated property for the days of the week, the only possible values are Monday through Sunday. You can control this by setting up an enumerated property in the .idl file: <BR><BR> typedef enum tagDAYSOFWEEK<BR> {<BR> Monday = 1,<BR> Tuesday = 2,<BR> Wednesday = 3,<BR> Thursday = 4,<BR> Friday = 5,<BR> Saturday = 6,<BR> Sunday = 7<BR> } DAYSOFWEEK; <BR>Visual Basic 5.0 has a feature called Code Completion. As you enter code, the editor displays a list of context-sensitive items that you can use in your code. In the case of an enumerated property, typing an "=" after the property causes Visual Basic to display a list of possible values. For example, a list of possible values to complete the following statement appears when you type: <BR><BR> mycontrol.DayOfWeek = <BR>Enumerated properties also allow you to browse the possible values for a property in a property browser. Look at the BorderStyle property for any control in the Visual Basic property browser. Possible values are displayed in a list box. By default, Visual Basic creates a list in the form of "1 [ASCII 150] Monday," "2 [ASCII 150] Tuesday," and so on. If you want to the change the display string, you need to override some methods in the IPerPropertyBrowsing interface. The Atlenum sample shows how to override the GetDisplayString(), GetPredefinedStrings(), and GetPredefinedValue() methods. The sample also implements a property page for modifying the enumerated property. <BR><BR>For additional information on how to implement enumerated properties in the Microsoft Foundation Classes (MFC), please see the following article in the Microsoft Knowledge Base: <BR>Q141488 SAMPLE: Using Enumerated Properties in an OLE Control <BR>If you are converting MFC projects to ATL, you can leave out the tag after the enum keyword in an .odl file, as in the following example: <BR><BR><BR><BR> typedef enum<BR> { <BR>... <BR><BR> } DAYSOFWEEK; <BR><BR>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<BR>In an .idl file, you need to have a tag after the enum keyword to ensure that you have the right type information: <BR><BR> typedef enum tagDAYSOFWEEK<BR> {<BR> ...<BR> } DAYSOFWEEK; <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-12-04 10:27:29
<br>内容:勇敢的心72 你的这种方法跟 zhangquan 的方法还不是一样的吗?
<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 + -