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]


비밀번호

댓글 작성자
 




... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
5132존기미3/3/201914625Physical Disk Access문의 [1]
5131강용규2/25/201913917c# 개발자입니다. 타이머 질문드립니다. [1]
5130노인코래방2/25/201918135C#에서 가장 좋은 성능을 보이는 파일 읽고 쓰는 방법이 무엇인가요? [2]
5129진우2/23/201917898닷넷 32비트 기반에서 메모리 부족으로 프로그램이 죽는경우 문의 [2]
5128게스트2/23/201915081안녕하세요. 초보개발자입니다. [3]파일 다운로드1
5127c#2/20/201913985책에 예제 문의드립니다. [2]
5125게스트2/19/201913811delegate를 활용한 event 를 적절히 불러오고 싶습니다. [2]
5124정근화2/12/201913853윈도우 서버2003 환경 오류 [2]
5123김주현2/8/201913681MS LUIS 에 대한 소개 하실 계획이 있으신가요? [1]
5122jaka...2/1/201915762Clickonce 배포 후 Command 실행 [2]파일 다운로드1
5121엔벌이1/31/201915392C# DataGridView의 MDB파일 함수? ArrayList? [1]파일 다운로드1
5120임우진1/30/201916549웹에서 응용프로그램 바로 실행하기 관련 브라우저에서 파라미터가 넘어오지 않습니다.ㅜㅜ [2]
5119guest1/29/201918121교재에 오탈자 있어 알려드리려 합니다 [1]
5118WPF꿈...1/26/201916105GetHashCode 메서드에 대해서 [1]
5117하주형1/25/201915870List<int>에 대한 이해가 잘안됩니다. [5]
5116게스트1/24/201914431asp.net 관련 gridview webform 질문 드립니다. [1]파일 다운로드1
5115Soul...1/24/201914654투명 패널 질문드립니다. [2]
5114박현일1/20/201915226WPF DataContext 관련 초보 질문을 드려봅니다.^^ [5]
5113하주형1/20/201914484안녕하세요 시작하세요 C# 인코딩관련 질문드립니다. [1]
5112손성배1/19/201923811안녕하세요 cp949 인스톨시 오류입니다... 너무 힘들어요 [5]
5111게스트1/10/201914983암호화 라이센스 관련 문의 드립니다. [1]
5110WPF꿈...1/9/201914463Thread Abort 함수 사용시 [2]
5109닷넷개발1/9/201914234thread 관련 질문 예제.. [2]파일 다운로드1
5108닷넷개발1/9/201915441thread 관련 질문 드립니다.. [4]
5107우코아1/4/201918202WPF에서 로딩중 이미지를 구현 - Project [5]파일 다운로드1
5106우코아1/3/201915840WPF에서 로딩중 이미지를 구현 - Source [1]
... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...