Git Product home page Git Product logo

Comments (18)

fafalone avatar fafalone commented on July 19, 2024 1

Right.

So for Unicode you have two options, String or LongPtr(StrPtr), with GetWindowText and W respectively. For ANSI there's just the one option but I don't think StrPtr with ANSI was ever popular.

from windevlib.

fafalone avatar fafalone commented on July 19, 2024 1

Ah RegEx, stuff of nightmares...

I'm leaving them in for calls that have 'As Any', in case the user wants to pass their own String-containing UDT, so if you could create a RegEx that accounts for that too, yeah that would be very helpful. It's not just for confusion; I and others still find myself copying from WDL into VB6, and removing it is a pain, so if it's not needed...

from windevlib.

fafalone avatar fafalone commented on July 19, 2024 1

I'll have to investigate where I was getting the type mismatches with LongPtr vs String, but for the most obvious issue here:

        Dim s As String
        s = "upper case"
        Dim s2 As String
        s2 = "upper case"
        Dim s3 As String
        s3 = "upper case"
        Dim s4 As String
        s4 = "upper case"
        Dim s5 As String
        s5 = "upper case"
        Dim s6 As String
        s6 = "upper case"
        Dim s7 As String
        s7 = "upper case"
        Dim s8 As String
        s8 = "upper case"
        
        CharUpperA(s)
        Debug.Print "A version with String: " & s 'UPPER CASE
        CharUpperA(StrPtr(s2))
        Debug.Print "A version with StrPtr: " & s2 'UPPER CASE    
        CharUpperW(s3)
        Debug.Print "W version with String: " & s3 'UPPER CASE
        CharUpperW(StrPtr(s4))
        Debug.Print "W version with StrPtr: " & s4 'UPPER CASE   
        CharUpper(s5)
        Debug.Print "Alias version with String: " & s5 'UPPER CASE
        CharUpper(StrPtr(s6))
        Debug.Print "Alias version with StrPtr: " & s6 'UPPER CASE
A version with String: UPPER CASE
A version with StrPtr: upper case
W version with String: upper case
W version with StrPtr: upper case
Alias version with String: UPPER CASE
Alias version with StrPtr: upper case

And:

Public Declare PtrSafe Function CharUpperW Lib "user32" (ByVal lpsz As LongPtr) As LongPtr

    Sub test2()
        Dim s As String
        s = "upper case"
        Dim l As LongPtr
        l = StrPtr(s)
        CharUpperW(l)
        Debug.Print "W version with LongPtr: " & s 'UPPER CASE
    End Sub

W version with LongPtr: UPPER CASE

Really appreciate the conversion by the way, haven't sat down to work on WDL since you posted it but I'll definitely be checking it out today.

from windevlib.

WaynePhillipsEA avatar WaynePhillipsEA commented on July 19, 2024 1

Passing StrPtr() result to a String param will only cause the compiler to issue a temporary string containing the stringified value of the object pointer, passing that temporary string to CharUpper.

from windevlib.

fafalone avatar fafalone commented on July 19, 2024 1

Yes that's the standard I've been using, minus the Wide on some of the W methods that hasn't been removed or will stay because of As Any.

from windevlib.

fafalone avatar fafalone commented on July 19, 2024 1

Thanks, me and everyone else still occasionally copying these to VB6 appreciates it. Will definitely mention your help in the readme. 🥇

==

They could pass String-containing UDTs with the aliased DeclareWide too, but the importance there is both the W version and the DeclareWide aliased version are Unicode-- it would be weird to mix in ANSI conversion with a Unicode call. And of course strings are still LongPtr. So I think it's preserving the pattern and consistency rather than breaking it, when it comes to how it's called, if not the keyword used in the declaration. WDL itself doesn't use any String arguments in UDTs associated with W APIs, so it's pretty unusual anyway I'd imagine.

DeclareWide without A/W versions... yeah, I haven't had a good handle on what to do here. It's hard to be consistent because the Windows API isn't consistent. Most are because there is no ANSI version. For some of these I've used overloads to allow either String or LongPtr on the same symbol, but I've been hesitant to go all in on that until I'm sure it's working ok and because I still intend to export WDL as a typelib for VB6/VBA when tB supports that. Beyond that, I've really just been guessing whether String or LongPtr would be better. I try to stay consistent within the same API set (if applicable).

from windevlib.

fafalone avatar fafalone commented on July 19, 2024
  1. To provide easier compatibility with existing code using StrPtr

  2. tB doesn't allow substituting a LongPtr for a String (yet, at least), and sometimes you want to pass one that you've obtained from somewhere else (maybe not to that function specifically, but then I can't predict every use case, and consistency is important for a project like this-- every A/W API follows that pattern, or if it doesn't should be reported as an issue), so it's useful as an alternative-- otherwise, GetWindowText and GetWindowTextW would have absolutely no difference and you'd need to write your own LongPtr declare if you wanted to pass one.

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

Got it! So the DeclareWide will successfully process a String or a StrPtr for a ByVal String argument. Thanks for the explanation.

from windevlib.

fafalone avatar fafalone commented on July 19, 2024

They're each for one of those.

You would use StrPtr with GetWindowTextW, but not GetWindowText.

The DeclareWide on the W is superfluous and I'm slowly removing them.

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

Ahh ok. So eventually it will look like this:

Public Declare PtrSafe Function GetWindowTextA Lib "user32" (ByVal hWnd As LongPtr, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Public Declare PtrSafe Function GetWindowTextW Lib "user32" (ByVal hWnd As LongPtr, ByVal lpString As LongPtr, ByVal nMaxCount As Long) As Long
Public DeclareWide PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextW" (ByVal hWnd As LongPtr, ByVal lpString As String, ByVal nMaxCount As Long) As Long

I think that is what caused my confusion initially. Thanks!

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

They're each for one of those.

You would use StrPtr with GetWindowTextW, but not GetWindowText.

The DeclareWide on the W is superfluous and I'm slowly removing them.

BTW Jon, I know you are busy with juggling many balls. Let me know if you would like some "unskilled" labor for helping to remove the superfluous DeclareWides - sounds like an easy job for RegEx!

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

Ok, here is a proof on concept using wdAPI.twin from v7.9.392. Attached are four files:

  • wdAPI.twin - unmodified orginal
  • wdAPIChanged.twin - a new version with DeclareWide changed to Declare for W's without "As Any" in the argument list.
  • listMarkedChange.twin - a qc file with all unmodified declares that were marked to be changed in the second file above
  • listMarkedUnchange.twin - a qc file with all unmodified declares that were found to be superfluous but had "As Any" in the argument list and so were not changed in the second file above

Now that I have the code established, I can easily change if you want something different, or want me to run on the other files (or send you my code).

wdAPI.zip

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

One thing I just realized is that the DeclareWide version supports both String and StrPtr(String) calls. So wondering why you didn't go this route to make conversion easier (note the argument list in the second declare):

Public Declare PtrSafe Function CharUpperA Lib "user32" (ByVal lpsz As String) As String
Public DeclareWide PtrSafe Function CharUpperW Lib "user32" (ByVal lpsz As String) As String
Public DeclareWide PtrSafe Function CharUpper Lib "user32" Alias "CharUpperW" (ByVal lpsz As String) As String

Sub test()
    Dim s As String
    s = "upper case"
    CharUpperA(s)
    Debug.Print "A version with String: " & s 'UPPER CASE
    CharUpperA(StrPtr(s))
    Debug.Print "A version with StrPtr: " & s 'UPPER CASE    
    CharUpperW(s)
    Debug.Print "W version with String: " & s 'UPPER CASE
    CharUpperW(StrPtr(s))
    Debug.Print "W version with StrPtr: " & s 'UPPER CASE   
    CharUpper(s)
    Debug.Print "Alias version with String: " & s 'UPPER CASE
    CharUpper(StrPtr(s))
    Debug.Print "Alias version with StrPtr: " & s 'UPPER CASE
End Sub

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

I'll have to investigate where I was getting the type mismatches with LongPtr vs String, but for the most obvious issue here:

        Dim s As String
        s = "upper case"
        Dim s2 As String
        s2 = "upper case"
        Dim s3 As String
        s3 = "upper case"
        Dim s4 As String
        s4 = "upper case"
        Dim s5 As String
        s5 = "upper case"
        Dim s6 As String
        s6 = "upper case"
        Dim s7 As String
        s7 = "upper case"
        Dim s8 As String
        s8 = "upper case"
        
        CharUpperA(s)
        Debug.Print "A version with String: " & s 'UPPER CASE
        CharUpperA(StrPtr(s2))
        Debug.Print "A version with StrPtr: " & s2 'UPPER CASE    
        CharUpperW(s3)
        Debug.Print "W version with String: " & s3 'UPPER CASE
        CharUpperW(StrPtr(s4))
        Debug.Print "W version with StrPtr: " & s4 'UPPER CASE   
        CharUpper(s5)
        Debug.Print "Alias version with String: " & s5 'UPPER CASE
        CharUpper(StrPtr(s6))
        Debug.Print "Alias version with StrPtr: " & s6 'UPPER CASE
A version with String: UPPER CASE
A version with StrPtr: upper case
W version with String: upper case
W version with StrPtr: upper case
Alias version with String: UPPER CASE
Alias version with StrPtr: upper case

And:

Public Declare PtrSafe Function CharUpperW Lib "user32" (ByVal lpsz As LongPtr) As LongPtr

    Sub test2()
        Dim s As String
        s = "upper case"
        Dim l As LongPtr
        l = StrPtr(s)
        CharUpperW(l)
        Debug.Print "W version with LongPtr: " & s 'UPPER CASE
    End Sub

W version with LongPtr: UPPER CASE

Really appreciate the conversion by the way, haven't sat down to work on WDL since you posted it but I'll definitely be checking it out today.

I really messed up that code logic 😐 Sorry.

Ok, so we are back to:

Public Declare PtrSafe Function CharUpperA Lib "user32" (ByVal lpsz As String) As String
Public Declare PtrSafe Function CharUpperW Lib "user32" (ByVal lpsz As LongPtr) As LongPtr
Public DeclareWide PtrSafe Function CharUpper Lib "user32" Alias "CharUpperW" (ByVal lpsz As String) As String

Correct?

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

Ok, here is a proof on concept using wdAPI.twin from v7.9.392. Attached are four files:

  • wdAPI.twin - unmodified orginal
  • wdAPIChanged.twin - a new version with DeclareWide changed to Declare for W's without "As Any" in the argument list.
  • listMarkedChange.twin - a qc file with all unmodified declares that were marked to be changed in the second file above
  • listMarkedUnchange.twin - a qc file with all unmodified declares that were found to be superfluous but had "As Any" in the argument list and so were not changed in the second file above

Now that I have the code established, I can easily change if you want something different, or want me to run on the other files (or send you my code).

wdAPI.zip

Jon, I just noticed that the proof-of-concept I made using wdAPI.twin was not from your latest version of WDL. So once you've had a chance to look at that and provide feedback, I'll have to re-run.

from windevlib.

fafalone avatar fafalone commented on July 19, 2024

Ok, here is a proof on concept using wdAPI.twin from v7.9.392. Attached are four files:

* wdAPI.twin - unmodified orginal

* wdAPIChanged.twin - a new version with DeclareWide changed to Declare for W's without "As Any" in the argument list.

* listMarkedChange.twin - a qc file with all unmodified declares that were marked to be changed in the second file above

* listMarkedUnchange.twin - a qc file with all unmodified declares that were found to be superfluous but had "As Any" in the argument list and so were not changed in the second file above

Now that I have the code established, I can easily change if you want something different, or want me to run on the other files (or send you my code).

wdAPI.zip

Looking good. I'm going to attach the current version (in progress, not public) of WDL files I'd like run if you're able; there's a few others since I split up APIs a bit when wdAPI got to 80,000 lines.

Thanks, would have taken me forever since the list of things I'd rather do than mess with regex is long and painful 🤣

Sources.zip

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

No problem - looking for ways to contribute...

Here they are. Three folders: originals, modified, and qc. The files in qc folder can now be imported as modules into tB for easier viewing. wdSecurity had no changes applied.

wdl_240503.zip

from windevlib.

GCuser99 avatar GCuser99 commented on July 19, 2024

And I have another question - on your keeping the "superfluous" DeclareWide's with "As Any" for users to pass string-containing UDT's...

Can't they do that with the Aliased DeclareWide?

I'm asking because you've come up with a nice solution to the A/W DeclareWide stuff, but it requires users to know the "pattern" - traditional A/W definitions + an aliased DeclareWide. I'm wondering if the incremental benefit of breaking the pattern for some cases is worth foregoing consistency, especially in light of one of the main benefits of your WDL is to impose some degree of order on what has been chaos in the past. Just something to think about...

On a separate note - I noticed there are also some DeclareWide's defined for non-A/W-type declares - not sure if that is intentional or not.

If you need any more assistance let me know.

Mike

from windevlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.