[delphi] 델파이 DLL을 VC++에서 사용하기

* 델파이
uses
SysUtils, Classes;

{$R *.res}
//==================================================================
function dfSum(a,b:Integer):Integer; StdCall; export;
begin
result := a+b ;
end;

exports
dfSum;
//==================================================================

begin
end.

* VC++
//1
typedef int(WINAPI * dfSum) (int a, int b);
dfSum dll_func = NULL;

//2
//typedef void (LPPROC*)(int a, int b);

void CDel2VCDlg::OnOK()
{
// TODO: Add extra validation here

HINSTANCE hInst = NULL;
hInst = LoadLibrary( "del_calc.dll" );

if ( hInst != NULL ) {
//1
dll_func = (dfSum)GetProcAddress(hInst, "dfSum");
if (dll_func != NULL) {
int re = dll_func(1, 2);
//int re = (*dll_func)(1, 2); //이것도 됨

}

FreeLibrary(hInst);
}


CDialog::OnOK();
}
Posted by 코덴스

댓글을 달아 주세요