Programming - cpueblo.com

DLL Class Import/Export 예제


글쓴이 : 유광희 날짜 : 2002-05-13 (월) 16:39 조회 : 17805
DLL 호출 예.

매번 귀찮게 typedef 를 하고
LoadLibrary 를 하고
GetProcAddress 하고
FreeLibrary 하는 과정이 귀찮아 적어봅니다


#include "WAV2MMF.h"

HINSTANCE g_hInst;

int main(int argc, char* argv[])
{
        
        HINSTANCE hInst = LoadLibrary ("D:\\\\Mobile Top\\\\Project\\\\WavToMA2\\\\ConvertMedia\\\\ConvertMedia\\\\Debug\\\\ConvertMedia.dll");

        // 클래스 포인터 타입 지정
        typedef WAV2MMF* (*PFNCreateA1)();

        // DLL 에서 함수 읽어옴
        PFNCreateA1 pfnCreateA1 = (PFNCreateA1)GetProcAddress(hInst, TEXT("CreateWAV2MMF"));

        // 클래스 생성 함수 호출
        WAV2MMF* a = (pfnCreateA1)();

        // 클래스 자유롭게 사용!.!
        a->SetMaxPcmSize(5120000);
        a->Converting("c:\\\\a.wav", "d:\\\\output.mmf");
                
        // 클래스를 메모리에서 해제
        delete a;

        // DLL Close
        FreeLibrary (hInst);
        return 0;
}