锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 鎵瀹氫箟鐨?coclass 鍜屾帴鍙g殑綺劇‘鎻忚堪銆?br>鍙敓鎴愭紜?.NET Framework 綾誨畾涔夌殑緙栬瘧鍣紝濡?C# 緙栬瘧鍣ㄣ?br>鏈夊叧綾誨瀷搴撳埌紼嬪簭闆嗚漿鎹㈣鍒欑殑鐭ヨ瘑銆?/p>
緙栧啓鑷畾涔夊寘瑁呮槸涓縐嶈緝?yōu)畱鋴社敤鐨勯珮珩旀妧鏈傛湁鍏崇敓鎴愯嚜瀹氫箟鍖呰鐨勫叾浠栦俊鎭紝璇峰弬瑙?a onclick="javascript:Track('ctl00_LibFrame_ctl04|ctl00_LibFrame_ctl11',this);" >鑷畾涔夋爣鍑嗗寘瑁?/font>銆?br>
涓 寤虹珛ATL COM 錛屽鍔犳帴鍙Test鍜屽疄鐜板嚱鏁癟est錛屽鍔犱互涓嬪嚱鏁幫細(xì)
idl鏂囦歡錛?br>
interface ITest : IDispatch
{
[id(1), helpstring("method ADD")] HRESULT ADD([in] LONG x, [in] LONG y, LONG* z);
[id(2), helpstring("method UpperCase")] HRESULT UpperCase([in] CHAR A, CHAR* B);
[id(3), helpstring("method LowerCase")] HRESULT LowerCase([in] BSTR A, BSTR* B);
[id(4), helpstring("method Change")] HRESULT Change([in] VARIANT A, [out] VARIANT* B);
};
ITest鏂囦歡錛?br>
MIDL_INTERFACE("52CA8A5C-593D-4E2E-B58F-BB6C6604EAF2")
ITest : public IDispatch
{
public:
virtual /**//* [helpstring][id] */ HRESULT STDMETHODCALLTYPE ADD(
/**//* [in] */ LONG x,
/**//* [in] */ LONG y,
LONG *z) = 0;
virtual /**//* [helpstring][id] */ HRESULT STDMETHODCALLTYPE UpperCase(
/**//* [in] */ CHAR A,
CHAR *B) = 0;
virtual /**//* [helpstring][id] */ HRESULT STDMETHODCALLTYPE LowerCase(
/**//* [in] */ BSTR A,
BSTR *B) = 0;
virtual /**//* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Change(
/**//* [in] */ VARIANT A,
/**//* [out] */ VARIANT *B) = 0;
};
鍦═est涓疄鐜頒互涓婃帴鍙e嚱鏁般?br>
浜?鍦–#涓殑浣跨敤鏂規(guī)硶
1錛変嬌鐢↖DE涓殑reference鏉eference com錛岃繖涓箣鍓峜om蹇呴』鍏堟敞鍐岋細(xì)
2錛変嬌鐢ㄥ懡浠LBIMP ATLCOM.tlb /out:C:\ATLCOM.dll ,鐒跺悗referece鐢熸垚鐨凞LL錛坱blmp鍛戒護(hù)甯綘娉ㄥ唽com錛夈?br>
3錛?a onclick="javascript:Track('ctl00_LibFrame_ctl04|ctl00_LibFrame_ctl09',this);" >TypeLibConverter 綾?
TypeLibConverter 綾伙紙浣嶄簬 System.Runtime.InteropServices 鍛藉悕絀洪棿涓級鎻愪緵浜嗗皢綾誨瀷搴撲腑鐨?coclass 鍜屾帴鍙h漿鎹負(fù)紼嬪簭闆嗕腑鐨勫厓鏁版嵁鐨勬柟娉曘傛 API 灝嗙敓鎴愪笌 Tlbimp.exe 鐩稿悓鐨勫厓鏁版嵁杈撳嚭銆備笉榪囷紝涓?Tlbimp.exe 涓嶅悓鐨勬槸錛?strong>TypeLibConverter 綾誨彲浠ュ皢鍐呭瓨涓殑綾誨瀷搴撹漿鎹負(fù)鍏冩暟鎹?br>
4錛夎嚜瀹氫箟鍖呰
褰撶被鍨嬪簱涓嶅彲鐢ㄦ垨涓嶆紜椂錛屼竴縐嶅彲閫夌殑鍋氭硶鏄湪鎵樼婧愪唬鐮佷腑鍒涘緩綾繪垨鎺ュ彛鐨勯噸澶嶅畾涔夈傜劧鍚庯紝鐢ㄩ潰鍚戣繍琛屽簱鐨勭紪璇戝櫒鏉ョ紪璇戞簮浠g爜浠ョ敓鎴愮▼搴忛泦涓殑鍏冩暟鎹?
瑕佹墜鍔ㄥ畾涔?COM 綾誨瀷錛屽繀欏誨叿澶囦笅鍒楀悇欏癸細(xì)
涓?鍦–#鐨刢lient璋冪敤COM鎻愪緵鐨勬帴鍙o紝鎴戜滑鍙互鐪嬪埌鍦–#涓瑿OM鐨勬帴鍙e拰鍑芥暟琚彉鎹負(fù)濡備笅錛?br>Member of atlcom.TestClass錛?br>public TestClass();
public virtual void ADD(int x, int y, ref int z);
public virtual void UpperCase(sbyte A, ref sbyte B);
public virtual void Change(object A, out object B) ;
public virtual void LowerCase(string A, ref string B);
鍥?鏇村鍙互鍙傝冿細(xì)http://www.codeproject.com/dotnet/cominterop.asp
What is OLE?
OLE (Object Linking and Embedding) is Microsoft's component document technology. With OLE, it is possible to dynamically link files and applications together. An object is a combination of data and the application needed to modify that data. Objects can be embedded in or linked to documents created with a different application.
For instance, an Excel spreadsheet can be embedded within a Microsoft Word document using OLE. Double-clicking the embedded spreadsheet will launch Excel and allow the user to modify the sheet.
Some applications include small applets that are used to create objects. For instance, Microsoft Word includes a drawing tool (MS Draw) and a tool for manipulating characters as art (Text Art) which can be launched only via OLE.
For more information, visit Microsoft's Developer Network page at: http://msdn.microsoft.com/default.aspx
What are COM, COM+, and DCOM?
COM (Component Object Model) is Microsoft's component software architecture developed primarily for Windows. It is the foundation upon which OLE and ActiveX are based, and provides a means to re-use code without requiring re-compilation. In COM, a component is a platform-specific binary file that compliant applications and other components can utilize. Programs incorporating a component's services never have access to its internal data structure, but instead include pointers to its standardized interface. Thus, it is possible for components to interact with each other regardless of how they work or what language they are written in.
COM+ is an enhanced version of COM that provides better security and improved performance. DCOM (Distributed Component Object Model) is an extension of COM that allows applications and components to communicate with each other over a network.
For more detailed information about COM, COM+, DCOM, and related technologies, visit: http://www.microsoft.com/com/default.mspx
What is ActiveX?
ActiveX is a term Microsoft uses to describe a number of its COM technologies. However, when most people say "ActiveX", they are really referring to ActiveX controls, Microsoft's answer to Java applets. The two technologies are similar in that they are designed to be downloaded and executed by web browsers. The difference is that while ActiveX controls can interface with Microsoft Windows better than Java can, they offer very little cross-platform support.
For more information about ActiveX controls as well as other ActiveX technologies, visit Microsoft's page at: http://www.microsoft.com/com/default.mspx CNET maintains a library of ActiveX controls, available at the following address: http://www.download.com/2001-2206-0.html?legacy=cnet
What are ActiveX controls?
ActiveX controls are small program building blocks that can be used to create distributed applications that work over the Internet through web browsers. Examples include customized applications for gathering data, viewing certain kinds of files, and displaying animation.
The ActiveX programming specification is an extension of Microsoft Windows and the Object Linking and Embedding (OLE) API. ActiveX applications are used mainly with Microsoft's Internet Explorer web browser.
Like Java applets, programs that use ActiveX controls run on the client computer, not the server.
For more information about ActiveX controls as well as other ActiveX technologies, visit Microsoft's page at: http://www.microsoft.com/com/default.mspx
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
A software architecture developed by Microsoft to build component-based applications. COM objects are discrete components, each with a unique identity, which expose interfaces that allow applications and other components to access their features. COM objects are more versatile than Win32 DLLs because they are completely language-independent, have built-in interprocess communications capability, and easily fit into an object-oriented program design. COM was first released in 1993 with OLE2, largely to replace the interprocess communication mechanism DDE used by the initial release of OLE. ActiveX also is based on COM.