Re: POLYTEXTOUT problems..( including declarations )



Hi J and Mike... thanks for replying...

So, if I am beginning to understand this correctly, it is OK for me to change
the declaration to fix this up?

ie: Change the declare from:
pptxt as POLYTEXT

to:
pptxt as Long

Is this correct?

When I was attempting to make this work, I tried using VarPtr(), but the compiler chucked it because the data type was incorrect
(struct vs. long)

I had thought that the declarations were Holy Scriptures, and that they could not be changed under any circumstances....

But now, if I am to understand this correctly, I can change the declaration to meet my requirements of sending different pointers?

Thanks a bunch,
Dan

(ORIGINAL CODE AT THE END OF THIS MESSAGE, FOR THOSE FOLLOWING ALONG)

"J French" <erewhon@xxxxxxxxxx> wrote in message news:434262ab.186362497@xxxxxxxxxxxxxxxxxxxxxxx
> On Tue, 4 Oct 2005 11:32:46 +0100, "Mike Williams"
> <Mike@xxxxxxxxxxxxxxxxx> wrote:
>
> >"Mike Williams" <Mike@xxxxxxxxxxxxxxxxx> wrote in message
> >news:dhtlfn$bcg$1@xxxxxxxxxxxxxxxxxxxxxxx
> >
> >. . . oops! I forgot to mention that in order to get the code working I had
> >to change the declaration to:
> >
> >Private Declare Function PolyTextOut& _
> > Lib "gdi32" Alias "PolyTextOutA" ( _
> > ByVal hdc As Long, _
> > pptxt As Rum, _
> > ByVal cStrings As Long)
> >
> >Having to do such a thing tells me for sure that I am going about all this
> >in a silly roundabout way, and that there is a far easier way of doing it,
> >but I haven't had my breakfast yet (slept in late today!). Never much good
> >before breakfast! (Probably simply changing your existing dynamic array for
> >a fixed size one will do the trick). Anyway, as I've said, there has got to
> >be a better way of doing this, but at least the example I posted shows that
> >the thing actually works ;-)
>
> Of course !
>
> You've spotted the problem, because the UDT contains Strings the UDT
> has to do a Unicode -> ANSI dance on the way down to the API
>
> Because the OP is just sending UDT(0) VB makes a converted copy of
> UDT(0) which is /not/ followed by UDT(1)
>
> By wrapping the lot in a UDT you are forcing conversion of a
> contiguous chunk of UDTs
>
> The other alternative is to send VarPtr( UDT(0) ) which sends the
> original memory, not a copy, but the problem with that is the Strings
> will still be in UniCrud
>
> However a quick check at MSDN reveals:
>
> Requirements
> Windows NT/2000/XP: Included in Windows NT 3.1 and later.
> Windows 95/98/Me: Unsupported.
> Header: Declared in Wingdi.h; include Windows.h.
> Library: Use Gdi32.lib.
> Unicode: Implemented as Unicode and ANSI versions.
>
> Which means changing "PolyTextOutA" to "PolyTextOutW" should sort
> out the problem, so VarPtr( UDT(0) ) is probably the way to go.
>
>

Original code:
'DECLARATIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Private Type POLYTEXT
x As Long
y As Long
n As Long
lpStr As String
uiFlags As Long
rcl As RECT
pdx As Long
End Type

Private Declare Function PolyTextOut& _
Lib "gdi32" Alias "PolyTextOutA" ( _
ByVal hdc As Long, _
pptxt As POLYTEXT, _
ByVal cStrings As Long)

'THIS WORKS:~~ (using a single struct)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Dim PT as POLYTEXT
Dim sBuf as String
Dim res as Long

sBuf$ = "My string"
PT.n = Len(sBuf$)
PT.lpStr = sBuf$

res& = PolyTextOut(My.hDC, PT, 1) 'this works..!!


'THIS DOES NOT WORK:~~ (uses an array in the call)~~~~~~~~~~~~~~~~~~~~~`
Dim aPT() as POLYTEXT
Dim sBuf1 as String
Dim sBuf2 as String

sBuf1$ = "String 1"
sBuf2$ = "String 2"

Redim aPT(0 to 1)

aPT(0).n = Len(sBuf1$)
aPT(0).lpStr = sBuf1$

aPT(1).n = Len(sBuf2$)
aPT(1).lpStr = sBuf2$

res& = PolyTextOut(My.hDC, aPT(0), 2) 'THIS HAS PROBLEMS..

.



Relevant Pages

  • Re: DhcpRequestParams from dhcpcsvc.dll
    ... it is because I do think that my own vb declaration is wrong, ... string to Unicode with StrConv and pass that as a string. ... Dim sendParams As DHCPAPI_PARAMS ...
    (microsoft.public.vb.winapi)
  • Re: DhcpRequestParams from dhcpcsvc.dll
    ... it is because I do think that my own vb declaration is wrong, ... string to Unicode with StrConv and pass that as a string. ... Dim recParams As DHCPAPI_PARAMS ... Dim sendParams As DHCPAPI_PARAMS ...
    (microsoft.public.vb.winapi)
  • Re: Prozedurnamen während Laufzeit auslesen
    ... Der Versuch, den Code von Chip Pearson anzupassen, schlägt leider fehl. ... ' If comment lines appear DIRECTLY below the procedured declaration (no ... Dim ProcName As String ...
    (microsoft.public.de.access)
  • Re: Prozedurnamen während Laufzeit auslesen
    ... Der Versuch, den Code von Chip Pearson anzupassen, schlägt leider fehl. ... ' If comment lines appear DIRECTLY below the procedured declaration (no ... Dim ProcName As String ...
    (microsoft.public.de.excel)
  • Re: Copying All Records from a Query to a Table
    ... It's almost always significantly better to use SQL than VBA. ... Dim strSQL As String ... You'd be well advised to require variable declaration: ...
    (microsoft.public.access.forms)