Main Menu

DLL 's

Started by monkeybot, October 13, 2008, 08:49:23 PM

Previous topic - Next topic

monkeybot

Is it possible to get multiple values returned from a dll(maybe a type or summat!)?
i can't seem to make it work... ???

kevin


  no, DLL functions only return a single value.

thaaks

Of course DLL functions (coded in C for example) can return pointers to structures.

But I am not sure if PB can wrap those back into something readable from within PB...

monkeybot

dllNo=getfreedll ()
loaddll "kernel32",dllNo
if not dllNo then end
;getdllexist
result = calldll (dllNo,"GetDiskFreeSpaceExW","c:\")
text 100,100,result
sync
waitkey

ok ...so how can i specify my return variable from GetDiskFreeSpaceExW

MSDN Says
BOOL WINAPI GetDiskFreeSpaceEx(
  __in_opt   LPCTSTR lpDirectoryName,
  __out_opt  PULARGE_INTEGER lpFreeBytesAvailable,
  __out_opt  PULARGE_INTEGER lpTotalNumberOfBytes,
  __out_opt  PULARGE_INTEGER lpTotalNumberOfFreeBytes
);


kevin

#4
 These are input parameters.

 __out_opt  PULARGE_INTEGER lpFreeBytesAvailable,
 __out_opt  PULARGE_INTEGER lpTotalNumberOfBytes,
 __out_opt  PULARGE_INTEGER lpTotalNumberOfFreeBytes


 What it's saying is that if you provide pointer to a each of these structures, the function will write it's return data into the structures you provide.  If you pass a null pointer (a zero) as one of those params, then it should ignore returning info.

  Be aware though,  In this particular case the functions are returning 64bit integers (PULARGE_INTEGER).   PB doesn't have a native 64bit type, so you'd have to write your own routine(s) to decipher the result (Convert it to string so you can display).

  Moreover,  when passing strings to functions, most (if not all)  WindowAPI  functions have two flavors.  An Ansi version and UU encode version.  Always choose the ANSI version of the function.   Which is norm ally the function name with an A appended to it.
 

PlayBASIC Code: [Select]
linkDll "Kernel32.dll"
GetDiskFreeSpaceEx(Folder$,lpFreeBytesAvailable,lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes) alias "GetDiskFreeSpaceExA" as integer
EndlinkDll

size=8

;create banks to store the 64bit data the function fills
Createbank 1,Size
Createbank 2,Size
Createbank 3,size

; get pointers to our return buffers
lpFreeBytesAvailable =getBankPtr(1)
lpTotalNumberOfBytes =GetBankPtr(2)
lpTotalNumberOfFreeBytes =getBankPtr(3)

; call it
result=GetDiskFreeSpaceEx("c:\",lpFreeBytesAvailable,lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes)

; display the results
if Result<>0
print "success"
for bank=1 to 3
print "BAnk:"+Str$(bank)
for lp=0 to size-1 step 4
print Hex$(PeekBankInt(Bank,lp))
next
next
else
print "call failed"
endif
Sync
WaitKey





monkeybot

#5
ahh i see,thanks a lot kevin.
It all makes sense now....