Programming Tips/MFC Advanced
DLL 만들기 1 - 뭐 부터 하지? DLL 구현..
Unikys
2007. 12. 5. 15:20
뭐부터 할까...
dll을 만들기 전에 가장 막막했던게 수 많은 프로젝트 중에서 어떤걸 만들어야할까..
dll도 MFC dll activex dll 등 참 많기도 하다...
그런데 dll 생성하는건 프로젝트 설정에서도 해줄 수 있으니 고민하지 말고 디버깅하기 편한, 익숙한
win32 console application으로 만들자..
그리고 일단 사용하려고하는 함수를 정의해야겠다..
데이터 smoothing을 위한 함수...
int Smoothing(float* inputData , int dataSize , float* &smoothingData , int& resultSize , int smoothingType)
로 일단 간단하게 정의해보자...
그럼 DLL로 만드는 소스 안에서는 어떻게 해야하나...
위키 피디아에서는..
#include <windows.h>
// Export this function
extern "C" __declspec(dllexport) double AddNumbers(double a, double b);
// DLL initialization function
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
// Function that adds two numbers
double AddNumbers(double a, double b)
{
return a + b;
}
이라고 되어있네...의미는 나중에 알아보기로 하고 무조건 따라해보자...
extern "C" __declspec(dllexport) int Smoothing(float* inputData , int dataSize , float* &smoothingData , int& resultSize , int smoothingType);
BOOL APIENTRY
DllMain(HANDLE hModule , DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
//smoothingData를 allocation해서 리턴한다.
int Smoothing(float* inputData , int dataSize , float* &smoothingData , int& resultSize , int smoothingType)
{
return 0;
}
int Smoothing(float* inputData , int dataSize , float* &smoothingData , int& resultSize , int smoothingType)
{
return 0;
}
Addnumber를 바꾸고 컴파일하니 이상은 없군...지금 win32 console, 컴파일을 exe로 하고 있으니 dll 생성하도록 바꿔보자..
Project-Properties-Configuration Properties-General-Configuration Type 에 가면
현재 Application(.exe)이다... dll로 바꾸고 컴파일 해보자..역시 성공..결과로..dll도 아래와 같이 생성됐다..
이 dll을 호출해서 이제 주물럭 거려야할 텐데...일단 테스트용을 위해서 함수 안에 테스트용 내용을 넣어보자...
{
resultSize = dataSize;
return resultSize;
}
return resultSize;
}
대충 들어오는 dataSize를 call by reference로 된 resultSize에 할당하고 리턴도 resultSize로 한다..
그럼 이제 호출하는 쪽으로 넘어가보자..