Windows Developer/VB
[VB] API로 만든 DLL 사용하기
빡썽
2010. 12. 7. 16:44
1. 프로젝트를 Visusl C++ - Win32 - Win32프로젝트로 설정
2. 설정을 DLL로 하고 빈 프로젝트로 한다
//cpp를 만들고 아래와 같이 DLL 함수를 만든다
extern "C" __declspec(dllexport) int AddInteger(int a, int b)//AddInterger
{
return a + b;
}
extern "C" __declspec(dllexport) int AddInteger(int a, int b)//AddInterger
{
return a + b;
}
3. 디버깅 전에 프로젝트에서 속성을 눌러서 일반->출력 디렉터리를 다음과 같이 \lib로 바꿔준다
4. 디버깅을 하고나면 프로젝트 내에 lib파일에 다음과 같이 dll파일과 lib파일이 생성된다.
[DLL을 사용할 프로젝트]
1.Visual Basic - Windows Forms 응용 프로그램을 선택
//버튼 클릭 이벤트에 다음과 같이 코드를 작성한다
Public Class Form1
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As Object
Result = AddInteger(3, 4) //Dll에서 만든 함수명
Label1.Text = "3+4 =" + Str(Result)
Label1.Text = "3+4 =" + Str(Result)
End Sub
End Class
End Class
2.프로젝트에서 모듈을 파일을 추가 시킨다
3.모듈 파일 안에 다음과 같은 코드를 작성한다
//AddInteger 함수 명 : "MyDll.dll" Dll 파일명
Module Module1
Module Module1
Declare Function AddInteger Lib "MyDll.dll" (ByVal A As Integer, ByVal B As Integer) As Integer
End Module
4. 출력 결과