ATL COM 쓰기                        조경민
                                오후 7:20 1999-09-27
-------------------------------------------------------
코드 구루에서 ATL COM 투토리얼을 전에 읽고 대충 정리한것..

1. VC++을 실행후 New/ New ATL COM App Wizard를 선택한다.
    Simple_ATL로 이름정하기
2. DLL 형식을 고른후 Finish를 선택한다.
3. 왼편 워크 스페이스에서 classView를 선택한후
    Simple_ATL 에서 오른클릭후 New ATL Object을 선택한다.
4. Objects와 Simple Object을 선택후 Next를 선택
5. Names 탭에서 이름을 정하고 First_ATL
6. Attributes에서 Interface : Custom 으로 Aggregation : NO
    로 한후 OK를 누른다.

7. 왼편 워크스페이스의 Classview에서 IFirst_ATL을 오른클릭
    후 Add Method를 선택한후 AddNum으로 하고
    파라미터리스트를 다음처럼한다.
    [in] long Num1, [in] long Num2, [out] long *ReturnVal

그리고 다음처럼 짠다.

STDMETHODIMP CFirst_ATL::AddNumbers(long Num1, long Num2,
long *ReturnVal)
{
        // TODO: Add your implementation code here        
        *ReturnVal = Num1 + Num2;
        return S_OK;
}

그리고 컴파일하면 dll이 생기고 이는 레지스트리에 등록되어
tlb형식라이브러리가 된다.

비베에서 실행하기
-----------------------------------------------------------
F2 참조에서 Simple_ATL v1.0 TypeLibrary를 선택한다ㅏ

Private Sub Command1_Click()    
    Dim objTestATL As SIMPLE_ATLLib.First_ATL
    Set objTestATL = New First_ATL        
    Dim lngReturnValue As Long    
    objTestATL.AddNumbers 5, 7, lngReturnValue    
    MsgBox "The value of 5 + 7 is: " & lngReturnValueEnd Sub

C++에서 쓰기


// You need to point this header file to the directory
// you placed the Simple_ATL project
#include "..\Simple_ATL\Simple_ATL.h"
#include <iostream.h>// Copy the following from the Simple_ATL_i.c file
// from the Simple_ATL project directoryconst IID IID_IFirst_ATL =
{0xC8F6E230,0x2672,0x11D3,{0xA8,0xA8,0x00,0x10,0x5A,0xA9,0x43,0xDF}};
const CLSID CLSID_First_ATL =
{0x970599E0,0x2673,0x11D3,{0xA8,0xA8,0x00,0x10,0x5A,0xA9,0x43,0xDF}};

void main(void){
// Declare and HRESULT and a pointer to the Simple_ATL interface        
        HRESULT                        hr;
        IFirst_ATL        *IFirstATL;        // Now we will intilize COM        
        hr = CoInitialize(0);
        // Use the SUCCEEDED macro and see if we can get a pointer         
        // to the interface
        if(SUCCEEDED(hr))        
        {
                hr = CoCreateInstance( CLSID_First_ATL, NULL,
                        CLSCTX_INPROC_SERVER,IID_IFirst_ATL,
                        (void**) &IFirstATL);                
                // If we succeeded then call the AddNumbers method,
                // if it failed
                // then display an appropriate message to the user.                
                if(SUCCEEDED(hr))                
                {
                        long ReturnValue;                        
                        hr = IFirstATL->AddNumbers(5, 7, &ReturnValue);
                        cout << "The answer for 5 + 7 is: " <<
                                ReturnValue << endl;
                        hr = IFirstATL->Release();                  
                }                
                else
                {
                        cout << "CoCreateInstance Failed." << endl;
                }
        }
        // Uninitialize COM        
        CoUninitialize();
}

'KB > tutorial' 카테고리의 다른 글

ATL 조금 하기  (0) 2004.03.19
VB With AutoCAD R14  (1) 2004.03.19
[mfc] Socket 프로그래밍  (4) 2004.03.19
[ActiveX] 디지털서명  (0) 2004.03.19
Active X 프로그램 짜기  (0) 2004.03.19

+ Recent posts