C# 클래스 인스턴스를 C 함수로 전달 할 때

hiluciano의 이미지

C# 클래스 인스턴스를 C 프로그램으로 전달하려고 하는데

먼저 C에서 만든 구조체는 다음과 같습니다.
typedef unsigned char BYTE;
typedef BYTE * BYTE_BUFFER;
typedef wchar_t * LPWSTR;
typedef struct
{
    size_t BytesDataCount; // BytesData의 원소 수
    BYTE_BUFFER * BytesData; // 이진 데이터들에 대한 배열 (BYTE** 형)
    size_t * BytesDataNCount; // BytesData[N] 에 있는 원소 수

    size_t StringsCount; // Strings의 원소 수
    LPWSTR * Strings;
    size_t * StringsNCount; // Strings[N]의 글자 수

    int Count[10];
} MyStruct, MYSTRUCT, *LPMYSTRUCT;

extern __declspec(dllexport) BOOL MyFunc001(IN LPMYSTRUCT __input, OUT LPMYSTRUCT __output);

아래는 C#에서 쓸 구조체입니다.
public class MyStruct
{
    [MarshalAs(UnmanagedType.U4)]
    private uint BytesDataCount;
    [MarshalAs(...? 이 부분을 어떻게? )]
    private List BytesData;
    [MarshalAs(UnmanagedType.LPArray)] // 여기도 이렇게 LPArray 쓰는거 맞는지...?
    private uint[] BytesDataNCount;

    [MarshalAs(UnmanagedType.U4)]
    private size_t StringsCount; // Strings의 원소 수
    [MarshalAs(...? 역시 이 부분을 어떻게?)]
    private List Strings;
    [MarshalAs(UnmanagedType.LPArray)] // 여기도 이렇게 LPArray 쓰는거 맞는지...?
    private size_t * StringsNCount; // Strings[N]의 글자 수

    [MarshalAs(UnmanagedType.I4, SizeConst = 10)]
    private int[] Count;
}

[DllImport("MyDll.DLL")]
public static extern bool MyFunc001(ref MyStruct __input, ref MyStruct __output);

BytesData, Strings 멤버에서 MarshalAs 속성의
타입을 어떻게 주어야 하는지 궁금합니다.
UnmanagedType.LPStruct, UnmanagedType.ByVal*** 등등 하나씩 다 해보고 있는 중인데
여기에서 아예 막히네요 ㅠㅠ

UnmanagedType.SafeArray보다는 그냥 이중 포인터 배열로 C 함수에 넘기고 싶은데
어떻게 해야 하나요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.