LPSTR_TEXTCALLBACK

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
ArneOrtlinghaus
Posts: 412
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

LPSTR_TEXTCALLBACK

Post by ArneOrtlinghaus »

When trying to compile the GUI classes furnished by Vulcan with the new compiler I get for the following line
#define LPSTR_TEXTCALLBACK PSZ(_CAST, 0xFFFFFFFF)
the error
Error XS9068 The compiler generated an automatic conversion to PSZ. This may create a memory leak in your application. Please use String2Psz() to let the compiler manage the lifetime of the PSZ or use StringAlloc() and manage the lifetime of the PSZ yourself.

I ask me how to resolve this ugly piece of code, since it is a casting of a number into a string.

Looking to the original C code I can see that already there is the same ugly code:
#define LPSTR_TEXTCALLBACKW ((LPWSTR)-1)

Arne
User avatar
ArneOrtlinghaus
Posts: 412
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

LPSTR_TEXTCALLBACK

Post by ArneOrtlinghaus »

Oops, spying with ILSpy into the VOWin32APILibrary delivered with X# shows that it seems to need quite a lot of tricks to get that work:

public static initonly LPSTR_TEXTCALLBACK := Xs_0024PSZLiteralsTable.__0024psz__0024460 as __Psz

internal static class Xs_0024PSZLiteralsTable
internal static initonly __0024psz__0024460 := __Psz{(IntPtr)(-1)} as __Psz
internal static initonly __0024psz__0024457 := __Psz{(IntPtr)(-1)} as __Psz
internal static initonly __0024psz__0024458 := __Psz{"frames"} as __Psz
internal static initonly __0024psz__0024459 := __Psz{"ms"} as __Psz
end class
User avatar
Chris
Posts: 4902
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

LPSTR_TEXTCALLBACK

Post by Chris »

Hi Arne,

This is just a warning, I'd say just ignore it, since this is just a fake PSZ created only once for the life time of the application and will not have any impact or anything.

Or maybe better just change it to PTR(_CAST, 0xFFFFFFFF), this should have the same effect I think and no compiler warning :)

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
ArneOrtlinghaus
Posts: 412
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

LPSTR_TEXTCALLBACK

Post by ArneOrtlinghaus »

Hi Chris,

thank you. When adding the message XS9068 to the warnings to be ignored, the dll compiled. I hope that tomorrow I have finished compiling the most important Dlls and can make the first Runtime tests.

Currently I am asking me, what this construct (casting a number to a string) does really mean. Also looking at it many times, it seems so strange.

Arne
User avatar
Chris
Posts: 4902
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

LPSTR_TEXTCALLBACK

Post by Chris »

Hi Arne,

I think this is just a "fake" PSZ, a constant with a special meaning for the specific functionality where it is used, this is why I said using PTR instead of PSZ will most probably work fine as well, and is more readable what it does actually.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply