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)
914오병태10/11/201015420감사드립니다. 염치없지만 또 한번 문의드립니다. [2]
912오병태10/11/201015713윈도우즈 인증서 관련해서 문의를 드립니다.
913정성태10/11/201019534    답변글 [답변]: 윈도우즈 인증서 관련해서 문의를 드립니다.
911나그네.10/6/201017927안녕하세요.. openssl 관련하여...혹시.. [2]
910윤용한9/17/201017531Visual Studio 2010으로 만든 Setup 파일을 Win2000 SP4에 설치 되게 할 수 없나요? [1]
908김재영9/7/201015776솔루션에 구성된 프로젝트의 버젼만 통합할려면 어떤 방법이 있습니까?
909정성태9/7/201017148    답변글 [답변]: 솔루션에 구성된 프로젝트의 버전만 통합할려면 어떤 방법이 있습니까? [1]
906임동찬8/19/201017360디버깅 중 이해할 수 없는 상황이 [1]
904김영태8/18/201018798C# Interop 관련 질문입니다. [1]
905김영태8/19/201020376    답변글 [답변]: C# Interop 관련 질문입니다. [4]
903임동찬8/17/201015502COM 객체의 타입 변경 [1]
902임동찬8/16/201015588DISPPARAMS 관련 질문 [4]
901노력자8/11/201019428.net 2008 c# 에서 만든 com+ 는 com탭에서 사용불가..?! [3]파일 다운로드1
900박정환8/9/201017868wsHttpBinding을 WS-Addressing 없이 세팅할 수는 없을 까요? [7]
899임동찬7/30/201018154WCF heartbeat 관련 질문 [3]
898이영기7/29/201015919.NET 웹용에서 함수호출에러 [1]
897임동찬7/16/201017575Visual Studio 2008에서 DB연결 관련 문제 [1]
894최종문7/14/201015971try/finally 에 관해서 문의 드립니다.
895정성태7/15/201015696    답변글 [답변]: try/finally 에 관해서 문의 드립니다.
896최종문7/15/201016901        답변글 [답변]: [답변]: try/finally 에 관해서 문의 드립니다. [1]
893이병준 donator7/7/201018477Visual Studio 2010 에서의 Build 관련 질문 [1]
889임동찬7/6/201016181아래 887번에 대한 추가 질문
890정성태7/6/201017552    답변글 [답변]: 아래 887번에 대한 추가 질문
891임동찬7/6/201017438        답변글 [추가]: [답변]: 아래 887번에 대한 추가 질문
892정성태7/6/201014700            답변글 [답변]: [추가]: [답변]: 아래 887번에 대한 추가 질문
888김재영7/5/201014365TFS에 반드시! SQL Report랑 SharePoint(or WSS)가 붙어야 합니까? [2]
... 61  62  63  64  65  66  [67]  68  69  70  71  72  73  74  75  ...