Microsoft MVP성태의 닷넷 이야기
글쓴 사람
쿠리마 (coolfh at empal.com)
홈페이지
첨부 파일
[code.zip]    

안녕하세요. 고수님들께 도움을 받기 위해 질문 올립니다.

C# COM Server 코드는 아래와 같습니다.

using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
using System.Reflection;

namespace MyInterop
{
    [Guid("3E0E2EB2-CC13-40fb-9346-34809CB2418C")]
    public interface IMyDotNetInterface
    {
        void ShowDialog(out tagUnitEx[] pArrUnit);
    }

    [ClassInterface(ClassInterfaceType.None)]
    [Guid("3A13EB34-3930-4e06-A3EB-10724CCC2F4B")]
    public class MyDotNetClass : IMyDotNetInterface
    {
        public MyDotNetClass() {}

        public void ShowDialog(out tagUnitEx[] pArrUnit)
        {
            tagUnitEx[] arrIndex;
            arrIndex = new tagUnitEx[3];

            arrIndex[0].strName = "coolfh";
            arrIndex[0].nIndex = 11;
            arrIndex[1].strName = "ssim";
            arrIndex[1].nIndex = 21;
            arrIndex[2].strName = "mist93";
            arrIndex[2].nIndex = 31;
            
            pArrUnit = arrIndex;
        }
    }

    public struct tagUnitEx
    {
        public string strName;
        public long nIndex;
    }
}

코드에서 처럼 tagUnitEx란 구조체에 string 및 long type의 맴버를 선언했고, Client쪽에서 pArrUnit을 요청하면 COM Server에서 배열의 크기(코드에서는 3)를 할당하고 값을 채워서 넘겨주는 방식입니다.

tagUnitEx 맴버로 long type만 선언했을 경우에는 잘 동작하는데요. string type 맴버를 추가했더니 에러가 발생합니다. (아래 코드 참조)

다음은 C++ Client 코드입니다.

m_pMyComp = IMyDotNetInterfacePtr(__uuidof(MyDotNetClass));

if(m_pMyComp)
{
            tagSAFEARRAY* psArrIndex = NULL;
        
            try
    {
        m_pMyComp->ShowDialog(&psArrIndex);
    }
    catch(_com_error &e)
    {
        CString strDescription = (LPCSTR)(e.Description());
        return TRUE;
    }

    tagUnitEx* pSaBuffer = NULL;
    ::SafeArrayAccessData(psArrIndex, reinterpret_cast<void HUGEP**>(&pSaBuffer));
    ::SafeArrayUnaccessData(psArrIndex);

             return TRUE;
}


위의 코드에서 m_pMyComp->ShowDialog(&psArrIndex); 여기서 에러가 발생하며, error description에는 "이전 형식이거나 잘못된 형식 라이브러리입니다." 라고 보여집니다.

구조체 맴버에 스트링이 없으면 잘 동작하는 코드인데요.

어떤 방법이던 간에 스트링을 포함한 구조체 배열을 C# 컴포넌트에서 C++ Client로 out(또는 ref)로 넘길 수만 있으면 됩니다.

코드를 첨부합니다.

고수님들의 조언 부탁드립니다.

좋은 하루 되세요.








[최초 등록일: ]
[최종 수정일: 9/29/2006]


비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  [68]  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
888김재영7/5/201014366TFS에 반드시! SQL Report랑 SharePoint(or WSS)가 붙어야 합니까? [2]
887임동찬7/2/201015670WCF sendTimeout에 관하여... [1]
886김재영6/16/201015691스레드 선언시 (Parameterized/)ThreadStart에 정의되는 메소드의 위치에 질문이 있습니다. [3]
885장근배6/13/201023100Win32Exception 창 핸들 에러 [1]
883채동민6/10/201015283비동기 DB 쿼리관련 질문
884정성태6/10/201016737    답변글 [답변]: 비동기 DB 쿼리관련 질문
881최준영5/24/201016512load되지않은 아이템 load하는 방법? [1]
880임상일5/10/201018607VS2010 TestManager를 통한 UI Test 관련 질문입니다. [2]파일 다운로드1
879정용훈5/3/201019846wcf 인증 문제 [2]
878채동민4/20/201019042WCF에서 maxItemsInObjectGraph 오류 관련 질문드립니다. [2]
872날쌘돌이4/8/201021749Windows7 에서 IIS에서 폼인증 으로 디버깅.. [1]파일 다운로드1
871영초4/7/201017107실버라이트로 스캐너 구동 프로그램이 가능할까요? [1]
869김재영4/6/201015991이미 실행된 어셈블리 컨트롤 권한을 다른 어셈블리에서 가져올 수 있습니까? [2]
868Lime3/5/201019594WCF 에서의 DataTable 사용 [2]
867Dani...2/18/201019723Question - HTTP 401.3 on DELETE, PUT verbs [6]파일 다운로드1
865박근대2/16/201016204WCF 오류 문의. [1]
863날쌘돌이1/31/201018535ActiveX Cab에서 닷넷 dll 등록 [1]
862장근배1/28/201016274AppPolId를 알 수 있는 방법이 있는지요? [1]
864장근배2/1/201015933    답변글 [답변]: AppPolId를 알 수 있는 방법이 있는지요?
858생초보1/26/201016343안녕하세요.. 파일 생성 처리 문제로 .... [2]
857꼭지1/22/201022086How to support Basic + Windows authentication mode in WCF(RESTful service) [4]파일 다운로드2
856질의자1/13/201020045vcredist_x86 배포 관련 여쭙습니다. [1]
855임동찬1/13/201018143이벤트 핸들러와 쓰레드의 관계 2 [4]파일 다운로드2
854임동찬1/12/201018428이벤트 핸들러와 쓰레드의 관계 [1]
853장근배1/12/201018033압축 프로그램,, [1]
852임동찬1/6/201015425base.OnStart(agrs) [1]
... 61  62  63  64  65  66  67  [68]  69  70  71  72  73  74  75  ...