게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
dll 랩퍼에 대해서 배우는 중인데 질문좀할께요 ㅠㅠ
게시물ID : programmer_21610짧은주소 복사하기
작성자 : 우와우와우왕
추천 : 0
조회수 : 470회
댓글수 : 3개
등록시간 : 2017/10/31 17:13:44
옵션
  • 본인삭제금지



TestCSharpLibrary.cs



using System;

using System.Runtime.InteropServices;

 

namespace TestCSharpLibrary

{

    public class TestCSharpLibrary

    {

        // From c++ DLL (unmanaged)

        [DllImport("TestCPPLibrary")]

        public static extern float TestMultiply(float a, float b);

 

        // From c++ DLL (unmanaged)

        [DllImport("TestCPPLibrary")]

        public static extern float TestDivide(float a, float b);

 

 

        [DllImport("TestCPPLibrary")]

        public static extern int ReturnInteger(int a);

 

 

        public static float SharpMultiply(float a, float b)

        {

            return (a * b);

        }

 

        public static float SharpDivide(float a, float b)

        {

            if(b==0)

            {

                return 0;

            }

 

            return (a / b);

        }

    }

}

 





 

TestCPPLibrary.cpp



 #include "TestCPPLibrary.h"

extern "C"

{

//      int i=5;

 

        float TestMultiply(float a, float b)

        {

               return a * b;

        }

 

        float TestDivide(float a, float b)

        {

               if (b == 0)

               {

                       return 0;

               }

 

               return a / b;

        }

 

 

        int ReturnInteger(int a)

        {

               return a;

        }


}

 

 

 



TestCPPLibrary.h


#ifdef TESTFUNCDLL_EXPORT

#define TESTFUNCDLL_API __declspec(dllexport)

#else

#define TESTFUNCDLL_API __declspec(dllimport)

#endif

 

extern "C"

{

        TESTFUNCDLL_API float TestMultiply(float afloat b);

        TESTFUNCDLL_API float TestDivide(float afloat b);

        TESTFUNCDLL_API int ReturnInteger(int a);

}



위와 같이 코드를 짜고 나온 dll 을 모두다 유니티 안에 넣은후에


아래와 같은 코드를 작성하였습니다


using System.Collections;

using System.Runtime.InteropServices;

using System.IO;

using UnityEngine;

 

public class UseDll : MonoBehaviour {

 

    [DllImport("TestCPPLibrary", EntryPoint = "TestDivide")]

    public static extern float StraightFromDllTestDivide(float a, float b);

 

 

    [DllImport("TestCPPLibrary", EntryPoint = "TestMultiply")]

    public static extern float StraightFromDllTestMultiply(float a, float b);

 

 

    [DllImport("TestCPPLibrary", EntryPoint = "ReturnInteger")]

    public static extern int HaveInteger(int a);

 

 

    void Start()

    {

        float multiplyResult = TestCSharpLibrary.TestCSharpLibrary.SharpMultiply(3, 5);

 

        float divideResult = TestCSharpLibrary.TestCSharpLibrary.TestDivide(15, 3);

 

        float straightFromDllDivideResult = StraightFromDllTestDivide(20, 5);

 

        float straightFromDllMultiplyResult = StraightFromDllTestMultiply(20, 5);

 

        Debug.Log(multiplyResult);

        Debug.Log(divideResult);

        Debug.Log(straightFromDllDivideResult);

        Debug.Log(straightFromDllMultiplyResult);

    }

 

       

        // Update is called once per frame

        void Update ()

    {

               if(Input.GetButtonDown("Fire1"))

        {

            int i = TestCSharpLibrary.TestCSharpLibrary.ReturnInteger(5);

            Debug.Log(i);

        }

        }

}

 




유튜브 영상을 보고 만든 코드구요 처음에는 곱하고, 나누는 함수들만 테스트를 하는데 잘 작동이 되더라구요


그래서 제가 직접 해보고 싶어서 ReturnInteger(int a) 라는 매개변수로 정수를 받으면, 해당 정수를 그대로 반환하는 간단한함수를 C++에서 만들고


그것을 그대로 유니티에서 임포트 하였습니다.


그런데 문제는 바로 위에 연한 주황색으로 칠한 부분에서 


 entrypointnotfoundexception


라는 글과 함께 게임 실행이 멈추어 버리네요 ㅠㅠ...


문법도 똑같이 하였고, 어떤 문법 에러도 발생하지 않는데 저런식으로 나와버리니 너무 골치아프네요...;;


새로 컴파일 한 후에 dll 파일도 유니티에 새로 넣어줬는데도 계속 안되니 도무지 모르겠네요 ㅠㅠ...

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호