EXPORTS WEP
char* pszBuffer; .... pszBuffer = (char *) LocalAlloc (LPTR, 20); ... LocalFree (pszBuffer);
HGLOBAL hglb; char* pszBuffer; hglb = GlobalAlloc (GHND, 2048); // GHND moveable 하며 0으로 초기화되는 메모리를 할당한다. // 2048은 할당되는 메모리의 크기 pszBuffer = GlobalLock (hglb); ... GlobalUnlock (hglb); GlobalFree (hglb);
C 코드 예제, DISKINFO.C: #include <windows.h> #include <dos.h> int CALLBACK LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine) // 다음은 윈도우 3.1에서만 필요한 UnlockData()이다 { if (wHeapSize > 0) UnlockData (0); //라이브러리의 데이터 세그먼트를 Unlocks return 1; } void __export CALLBACK GetDiskInfo (char *cDrive, char *szVolumeName, unsigned long *ulFreeSpace) { unsigned drive; struct _diskfree_t driveinfo; struct _find_t c_file; _dos_getdrive (&drive); _dos_getdiskfree( drive, &driveinfo ); if (!_dos_findfirst( "*.*", _A_VOLID, &c_file )) wsprintf( szVolumeName, "%s", c_file.name); else wsprintf ( szVolumeName, "NO LABEL"); *cDrive = drive + 'A' -1; *ulFreeSpace = (unsigned long) driveinfo.avail_clusters * (unsigned long) driveinfo.sectors_per_cluster * (unsigned long) driveinfo.bytes_per_sector; } DISKINFO.DEF 파일 예제 LIBRARY diskinfo DESCRIPTION 'GetDiskInfo 는 VB에서 콜된다. EXETYPE WINDOWS 3.1 CODE PRELOAD MOVEABLE DISCARDABLE DATA PRELOAD MOVEABLE SINGLE HEAPSIZE 4096 EXPORTS GetDiskInfo @1
Declare Sub getdiskinfo Lib "c:\somepath\diskinfo.dll" (ByVal mydrv As String, ByVal myvol As String, free As Long)
' 다음은 Declare 부분 Declare Sub getdiskinfo Lib "c:\dllartic\diskinfo.dll" ( ByVal mydrive As String, ByVal myvolume As String, free As Long)
Sub Command1_Click () Dim drive As String * 1 Dim volume As String * 20 Dim free As Long Call getdiskinfo(drive, volume, free) Text1.Text = drive Text2.Text = volume Text3.Text = Str$(free) End Sub
vnote