Recent

Author Topic: [SOLVED] Conversion between ordinals and pointers not portable  (Read 12137 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
[SOLVED] Conversion between ordinals and pointers not portable
« on: January 29, 2013, 03:55:20 am »
Question is updated.

Code: [Select]
PrevWndProc:=Windows.WNDPROC(SetWindowLongPtr(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)));
on execution of above subclassing code following hints is displayed in message window.
Quote
unit1.pas(93,37) Hint: Conversion between ordinals and pointers is not portable

Quote
at : PtrInt(@WndCallback)  location
« Last Edit: January 30, 2013, 02:13:37 pm by deepaak99 »
Holiday season is online now. :-)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Message Intercepting Problem
« Reply #1 on: January 29, 2013, 04:00:03 am »
Code: [Select]
procedure WMDeviceChange(var Msg: TMessage);It's missing "TForm1.". Compiler should give error about WMDeviceChange declaration exists but no implementation.

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Message Intercepting Problem
« Reply #2 on: January 29, 2013, 04:08:07 am »
Code: [Select]
procedure WMDeviceChange(var Msg: TMessage);It's missing "TForm1.". Compiler should give error about WMDeviceChange declaration exists but no implementation.

sorry, it was writing mistake, the result is same. No intercepting is ever occurred.
Holiday season is online now. :-)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Conversion between ordinals and pointers not portable
« Reply #3 on: January 29, 2013, 07:31:26 pm »
how to remove this warning/hint
Holiday season is online now. :-)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Conversion between ordinals and pointers not portable
« Reply #5 on: January 30, 2013, 03:50:50 am »
http://forum.lazarus.freepascal.org/index.php/topic,19380.msg110826.html#msg110826

it works like a charm..
Code: [Select]
SetWindowLong(WidgetSet.AppHandle,GWL_WNDPROC,{%H-}PtrInt(@WndCallback))
Quote
{%H-}
is used to remove the Hint warning for particular point as used in above code.

but is it safe to use {%H-} , because it only removes the hint message from being displayed.  :-\

Is there any other way to make compiler happy without using {%H-}

« Last Edit: January 30, 2013, 03:54:26 am by deepaak99 »
Holiday season is online now. :-)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Conversion between ordinals and pointers not portable
« Reply #6 on: January 30, 2013, 09:39:03 am »
Quote
{%H-}
is used to remove the Hint warning for particular point as used in above code.

but is it safe to use {%H-} , because it only removes the hint message from being displayed.  :-\
Compiler hints indicate something *may* be wrong, but the compiler does not have enough information to be sure.
Is it safe to disable a hint?
The compiler does not know, only you, the programmer, can know
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Conversion between ordinals and pointers not portable
« Reply #7 on: January 30, 2013, 02:12:23 pm »
Quote
{%H-}
is used to remove the Hint warning for particular point as used in above code.

but is it safe to use {%H-} , because it only removes the hint message from being displayed.  :-\
Compiler hints indicate something *may* be wrong, but the compiler does not have enough information to be sure.
Is it safe to disable a hint?
The compiler does not know, only you, the programmer, can know

This is awsesome, thank you sir  :)
Holiday season is online now. :-)

MrAndreas

  • Newbie
  • Posts: 2
Re: [SOLVED] Conversion between ordinals and pointers not portable
« Reply #8 on: April 26, 2017, 09:47:21 am »
There may be a potential issue and why the hint is shown. Take my situation, for example...

var
  LPSID: PWideChar;
begin
  // ...
    LocalFree(THandle(LPSID)); // Hint: Conversion between ordinals and pointers not portable
  // ...
end.

My current build environment is 64-bit with a 64-bit Unicode target, but what if I then want to build a 32-bit version? Would I not be running into a conversion error then or does the definition of PWideChar change to one compatible with THandle?

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4458
  • I like bugs.
Re: [SOLVED] Conversion between ordinals and pointers not portable
« Reply #9 on: April 26, 2017, 10:16:35 am »
MrAndreas, first can you please confirm that you are not a bot or spammer. Your first message on this board was a reply to an over 4 years old thread. Your code example also makes no sense which is suspicious. And what means "64-bit Unicode"?
« Last Edit: April 26, 2017, 11:48:40 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

MrAndreas

  • Newbie
  • Posts: 2
Re: [SOLVED] Conversion between ordinals and pointers not portable
« Reply #10 on: April 27, 2017, 04:43:35 am »
Doh! Silly me. THandle and Pointer (as in Pointer to WideChar) will always be of the same size no matter if it's a 32-bit or 64-bit target. Doh! :) I just wish there was a tidier solution than using compiler directives to indicate to the compiler that the conversion is safe without it generating a hint.

Here's the definition of THandle that I didn't take into consideration in my original reply.

{$ifdef CPU64}
  THandle = QWord;
{$else CPU64}
  THandle = DWord;
{$endif CPU64}

P.S. No, I'm not a bot or spammer, I've just been looking for a solution to my compiler hint and this thread came up on top when Googling. Originally I questioned the answer but then, as can be seen by my followup reply, I realised I was completely off.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4458
  • I like bugs.
Re: [SOLVED] Conversion between ordinals and pointers not portable
« Reply #11 on: April 27, 2017, 08:49:46 am »
Doh! Silly me. THandle and Pointer (as in Pointer to WideChar) will always be of the same size no matter if it's a 32-bit or 64-bit target. Doh! :) I just wish there was a tidier solution than using compiler directives to indicate to the compiler that the conversion is safe without it generating a hint.
THandle can be anything. The typecast is not safe.
Why would you want to cast a Pointer to a THandle? A typecast always means the original type is wrong and must be forced to something else. Just use the right types and no casting is needed.

Quote
Here's the definition of THandle that I didn't take into consideration in my original reply.
Code: [Select]
{$ifdef CPU64}
  THandle = QWord;
{$else CPU64}
  THandle = DWord;
{$endif CPU64}
Where did you find that? FPC's system defines it as
Code: [Select]
THandle = Longint;
LCL defines its own as
Code: [Select]
THandle = type PtrUInt;
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018