calling windows dll

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

calling windows dll

Post 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
User avatar
robert
Posts: 4555
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

calling windows dll

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

calling windows dll

Post by kevclark64 »

Robert, thanks for that information.
Post Reply