xsharp.eu • LPSTR_TEXTCALLBACK
Page 1 of 1

LPSTR_TEXTCALLBACK

Posted: Mon Nov 05, 2018 9:36 am
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

LPSTR_TEXTCALLBACK

Posted: Mon Nov 05, 2018 9:46 am
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

LPSTR_TEXTCALLBACK

Posted: Mon Nov 05, 2018 3:39 pm
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

LPSTR_TEXTCALLBACK

Posted: Mon Nov 05, 2018 3:53 pm
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

LPSTR_TEXTCALLBACK

Posted: Mon Nov 05, 2018 10:42 pm
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