linedda function from gdi32

Just starting out? Need help? Post your questions and find answers here.
startup
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Feb 25, 2015 5:55 pm

linedda function from gdi32

Post by startup »

can anybody give me a hint how to obtain a reference to this function:
linedda from gdi32

Code: Select all

BOOL LineDDA(
  _In_ int         nXStart,
  _In_ int         nYStart,
  _In_ int         nXEnd,
  _In_ int         nYEnd,
  _In_ LINEDDAPROC lpLineFunc,
  _In_ LPARAM      lpData
);
HELP
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: linedda function from gdi32

Post by netmaestro »

Stand by for hint...

coming...

Here is the hint:

Code: Select all

Procedure callback(x, y, lParam)
  Debug Str(x)+", "+Str(y)
EndProcedure

LineDD_(0,0,100,160,@callback(),0)
Hint successfully delivered. Contains a working sample. Reference is here: https://msdn.microsoft.com/en-us/librar ... s.85).aspx
BERESHEIT
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: linedda function from gdi32

Post by bbanelli »

Hi netmaestro,

regardless OP's incoherent post, he might be on something, since both PB 5.31 and latest PB 5.4 b8 return something like this. Tried on Win XP, W7 x64 and W10 x64.

Image
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
startup
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Feb 25, 2015 5:55 pm

Re: linedda function from gdi32

Post by startup »

this is exactly what happen to me too. it doesn't work and i think its a purebasic (lib) problem. is there any other way to use that function, any trick, any workaround?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: linedda function from gdi32

Post by netmaestro »

Ok, I see the issue you're referring to. Here's a version that will work under unicode or ascii:

Code: Select all

CompilerIf #PB_Compiler_Unicode = #True
  Import "gdi32.lib"
    LineDDA(x1, y1, x2, y2, *callback, lParam)
  EndImport
CompilerElse
  Macro LineDDA
    LineDD_
  EndMacro
CompilerEndIf

Procedure callback(x, y, lParam)
  Debug Str(x)+", "+Str(y)
EndProcedure

LineDDA(0,0,100,160,@callback(),0)
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: linedda function from gdi32

Post by IdeasVacuum »

.... Danilo posted a very handy GDI+ lib:
gDrawing
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: linedda function from gdi32

Post by bbanelli »

netmaestro wrote:Ok, I see the issue you're referring to. Here's a version that will work under unicode or ascii:
Thanks, works perfectly, but could you just briefly clarify what's the issue in this case?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
startup
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Feb 25, 2015 5:55 pm

Re: linedda function from gdi32

Post by startup »

thanks a million - that works.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: linedda function from gdi32

Post by netmaestro »

could you just briefly clarify what's the issue in this case?
It's actually quite a common problem that crops up from time to time. If you have the "Compiler Options -> Create Unicode Executable" checked then the linker will search for a unicode version of the function from the library (with the name usually ending in "W"), as opposed to the name ending in "A" which is the ascii version. If you check gdi32.lib you will see that there is no "LineDDW" version of this function, all there is is the ascii one. But when you compile under unicode the linker won't link the ascii version in with your exe - you have to force it using code like I posted. If you think about what the function does, there really is no need for MS to have included a unicode-ready version - no strings involved. But PB could utilize a macro or something to get the function into the program seamlessly. It actually could be considered a bug, losing access to a non-string function because you flipped the Unicode switch.
BERESHEIT
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: linedda function from gdi32

Post by bbanelli »

netmaestro wrote:
could you just briefly clarify what's the issue in this case?
It's actually quite a common problem that crops up from time to time. If you have the "Compiler Options -> Create Unicode Executable" checked then the linker will search for a unicode version of the function from the library (with the name usually ending in "W"), as opposed to the name ending in "A" which is the ascii version. If you check gdi32.lib you will see that there is no "LineDDW" version of this function, all there is is the ascii one. But when you compile under unicode the linker won't link the ascii version in with your exe - you have to force it using code like I posted. If you think about what the function does, there really is no need for MS to have included a unicode-ready version - no strings involved. But PB could utilize a macro or something to get the function into the program seamlessly. It actually could be considered a bug, losing access to a non-string function because you flipped the Unicode switch.
Hi netmaestro, thank you very much for your explanation.

But how should one tell from Microsoft documentation that this is ASCII/ANSI only version of function, usually under "Requirements" tab is says something like "Unicode and ANSI names" so you can tell. But I can't see anything similar with this function, though...
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: linedda function from gdi32

Post by DontTalkToMe »

bbanelli wrote: how should one tell from Microsoft documentation that this is ASCII/ANSI only version of function, usually under "Requirements" tab is says something like "Unicode and ANSI names" so you can tell. But I can't see anything similar with this function, though...

Looking at the docs there is only one API function and it's named LineDDA.

http://winapi.freetechsecrets.com/win32 ... ctions.htm

For some reason PB thinks the function is named LineDD instead (so LineDD_ in PB) and thinks there should be an ascii (LineDDA) and a unicode (LineDDW) version of it.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: linedda function from gdi32

Post by bbanelli »

DontTalkToMe wrote:For some reason PB thinks the function is named LineDD instead (so LineDD_ in PB) and thinks there should be an ascii (LineDDA) and a unicode (LineDDW) version of it.
Oh, OK, that's where I got confused, probably because "DD" is capitalized so it's harder to "figure out" than MessageBoxA/W, for example.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: linedda function from gdi32

Post by Fred »

It was an error in the import declaration, should be fixed for the next beta.
Post Reply