This forum is meant for questions and discussions about the X# language and tools
SHirsch
Posts: 286 Joined: Tue Jan 30, 2018 8:23 am
Location: Germany
Post
by SHirsch » Fri Mar 16, 2018 4:02 pm
Hi all,
how can I import dll function with REF as parameter?
Code: Select all
_DLL FUNC MyFunction( param1 REF WORD ) AS DWORD PASCAL:MyDll.MyFunction
In X#/VO this compiles without error message. With X#/Core I get 'e
rror XS0214: Pointers and fixed size buffers may only be used in an unsafe context '
Background: I try to eliminate VO/Vulcan dependancies.
Regards,
Stefan
Chris
Posts: 4906 Joined: Thu Oct 08, 2015 7:48 am
Location: Greece
Post
by Chris » Fri Mar 16, 2018 4:58 pm
Hi Stefan,
This declaration should compile fine in Core, too. Are you sure the error is pointing in that declaration, or maybe it's reported in the code that calls it? Or in some other function?
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
Guy Deprez
Post
by Guy Deprez » Thu Mar 22, 2018 10:40 pm
With the code below, same error X0214 in X#/Core...
[DllImport("user32.dll")];
STATIC METHOD ShowWindow(hWnd AS PTR, nCmdShow AS INT) AS LOGIC PASCAL
Guy
Guy Deprez
Post
by Guy Deprez » Thu Mar 22, 2018 11:01 pm
Problem solved: PTR -> IntPTR
[DllImport("user32.dll")];
STATIC METHOD ShowWindow(hWnd AS IntPTR, nCmdShow AS INT) AS LOGIC PASCAL
Guy
Chris
Posts: 4906 Joined: Thu Oct 08, 2015 7:48 am
Location: Greece
Post
by Chris » Fri Mar 23, 2018 12:47 am
Hi Guy,
Just to explain, this is because the "PTR" type is a VO compatibility thing and it is not available in the Core dialect, only in the vulcan, VO and similar X# dialect settings. In Core, IntPtr can be used instead of PTR, as you already found!
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu