윈도우의 API 만을 가지고 윈속을 사용할때도 마찬가지 이지만.
무작정 socket함수를 호출한다고 소켓이 만들어져 통신이 성립되지 않는다.

MFC 를 사용하는 과정에서도 마찬가지로.
소켓 클래스를 사용하기위해서는 초기화 과정이 필요하다.

app클래스에서의 initinstance() 함수에서 초기화 하면된다.

if (!AfxSocketInit())
{
AfxMessageBox("socket init failure");
return FALSE;
}
2006/07/25 17:03 2006/07/25 17:03

정말 몰라서 바보 같은짓을 하고 있을지도 모르겠다.
개발환경이 바뀌었다고 이렇게 해매다니, MS에 저주를!!!! (솔직한 마음이었다.)

우선 VC++ 6.0에서 메소드를 추가하고 2003에서 그대로 반영하였더니 동작해서 그나마 다행.
(실제로 스크립트나 파일명등이 바뀌어 그대로 추가하면 안되는 경우도 다반사였기 때문)

1. 아래는 VC++ 6.0에서의 메소드 선언후 관련부분.

axtest.odl
----
dispinterface _DAxtest
{
properties:
// NOTE - ClassWizard will maintain property information here.
//    Use extreme caution when editing this section.
//{{AFX_ODL_PROP(CAxtestCtrl)
//}}AFX_ODL_PROP
methods:
// NOTE - ClassWizard will maintain method information here.
//    Use extreme caution when editing this section.
//{{AFX_ODL_METHOD(CAxtestCtrl)
[id(1)] void SetText();
//}}AFX_ODL_METHOD
[id(DISPID_ABOUTBOX)] void AboutBox();
};

AxtestCtrl.h
----
// Dispatch maps
//{{AFX_DISPATCH(CAxtestCtrl)
afx_msg void SetText();
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()

AxtestCtl.cpp
----
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CAxtestCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CAxtestCtrl)
DISP_FUNCTION(CAxtestCtrl, "SetText", SetText, VT_EMPTY, VTS_NONE)
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CAxtestCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()

AxtestCtl.cpp
----
void CAxtestCtrl::SetText()
{
// TODO: Add your dispatch handler code here
}

2.아래는 닷넷 2003에서 적용하기위한 소스코드.

axtest1.idl
----
dispinterface _Daxtest1
{
properties:
methods:

[id(2)] void test(void);
[id(DISPID_ABOUTBOX)] void AboutBox();
};

axtest1Ctrl.h
----
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
afx_msg void test(void);

axtest1Ctrl.cpp
----
BEGIN_DISPATCH_MAP(Caxtest1Ctrl, COleControl)
DISP_FUNCTION_ID(Caxtest1Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(Caxtest1Ctrl, "tet", 2 , test, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()

axtest1Ctrl.cpp
----
void Caxtest1Ctrl::test(void)
{
}

3. 결론은 외부 인터페이스 (Active-X 또한 COM 기반이므로)를 선언하기위해 IDL 파일에 명기를 하고, 헤더에는 afx_msg 를 이용하여 virtual 함수를 선언하고 이를 메시지 맵과 같은 Dispatch map 에 등록을 시켜 사용한다는것이다. 뭐 간단하기는 하지만 이 맵이 조금만 커지면 상당히 불편해 질것같다.

뭔가 클래스 위자드 같은 툴이 있을텐데... www.devpia.com에 질문을 올렸지만 아직까지는 답변이 안달렸다..T^T

============================================

5시간정도 해매다 결국 서점에서 책을 뒤지면서 찾은 해답...

클래스뷰의 인터페이스에서 오른버튼클릭!!!!

젠장..ㅠ,.ㅠ
2006/07/25 17:02 2006/07/25 17:02