xsharp.eu • calling windows dll
Page 1 of 1

calling windows dll

Posted: Mon Sep 28, 2020 7:26 pm
by kevclark64
How would this be converted from Foxpro to XSharp?

DECLARE Long GetLastError IN WIN32API
DECLARE Long SetDefaultPrinter In WINSPOOL.DRV String pPrinterName
DECLARE INTEGER GetDefaultPrinter IN winspool.drv STRING @ pszBuffer, INTEGER @ pcchBuffer

calling windows dll

Posted: Mon Sep 28, 2020 8:50 pm
by robert
Kevin,

Code: Select all

// traditional syntax
_DLL FUNCTION GetLastError as INT PASCAL:Win32API.GetLastError()

// dotnet syntax
[DllImport("Win32API.dll")];
FUNCTION GetLastError() AS INT PASCAL

[DllImport("winspool.drv", CharSet := CharSet.Ansi, EntryPoint :="SetDefaultPrinterA" )];
FUNCTION SetDefaultPrinter( pPrinterName as STRING) AS LOGIC PASCAL

[DllImport("winspool.drv", CharSet := CharSet.Ansi, EntryPoint :="GetDefaultPrinterA" )];
FUNCTION GetDefaultPrinter( pszBuffer as StringBuilder, pcchBuffer REF INT) AS LOGIC PASCAL
You can also change the last 2 calls and change the CharSet to CharSet.Unicode and change the "A" at the end of the function name to "W" to call the Unicode versions of these functions.


Robert

calling windows dll

Posted: Wed Sep 30, 2020 12:52 pm
by kevclark64
Robert, thanks for that information.