ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 07_C#_DLL 사용법
    프로그래밍/PEViewer 2019. 12. 23. 00:58

    C#의 문법에서는 변수명, 메서드를 선언할 때 클래스 안에 선언한다.

    이걸 몰라서 몇일 동안 왜 컴파일이 안되는지 헤멧다.... 바보같은 녀석 꼼꼼하게 찾아볼걸

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace CsharpClient
    {
        class CCC
        {
            [DllImport("\\\\vmware-host\\Shared Folders\\데스크탑\\Cosole\\Cosole\\bin\\Debug\\netcoreapp3.1\\Cdll.dll", CallingConvention = CallingConvention.Cdecl)]
            private static extern IntPtr getMessage();
    
            [DllImport("\\\\vmware-host\\Shared Folders\\데스크탑\\Cosole\\Cosole\\bin\\Debug\\netcoreapp3.1\\Cdll.dll", CallingConvention = CallingConvention.Cdecl)]
            private static extern void copyMessage(StringBuilder _input, StringBuilder _output);
        }
        
    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
        }
    }
    

    다음 코드에서는 에러가 발생하지 않고 제대로 함수를 인식하는 것을 확인할 수 있다.

     

    그리고 왠지는 모르겠지만 DllImport할 때 절대 경로로 dll 파일의 경로를 지정해주지 않으면 

    파일을 제대로 로드하지 못한다. 어떻게 해야 절대 경로를 사용하지 않을 수 있는지 모르겠다. 

    그리고 경로를 지정할때 \앞에 \를 붙여서 \\로 써야 \로 인식된다. 

    '프로그래밍 > PEViewer' 카테고리의 다른 글

    05_03_PE구조 그냥 출력_함수사용  (0) 2019.12.23
    05_02_PE구조정리_32bit_Console  (0) 2019.12.23
    06_DLL 제작 및 사용  (0) 2019.12.22
    05_PE구조 출력  (0) 2019.12.18
    04_바이트 순서 변환  (0) 2019.12.16

    댓글

lonun@네이버.com으로 연락해주세요!