Replies: 3 comments 9 replies
-
Hmm on 2nd inspection I do see an issue with using type aliases... you would need declare name aliases too... #if Unicode then
type StringX as StringW
const sAbortSystemShutdown as string = "AbortSystemShutdownW"
#else
type StringX as StringA
const sAbortSystemShutdown as string = "AbortSystemShutdownA"
#end if
Public Declare PtrSafe Function AbortSystemShutdown Lib "advapi32" alias sAbortSystemShutdown (ByVal lpMachineName As StringX) As Long |
Beta Was this translation helpful? Give feedback.
-
Symbols like |
Beta Was this translation helpful? Give feedback.
-
Granted I don't spend a ton of time in the VBA world, but my experience has been there's tons of superfluous conditional compilation.
This is valid in both 32bit and 64bit. You only need a version without More on the point here... the thing is, VB/tB strings are already Unicode. What's happening with APIs is behind the scenes, VB creates a temporary ANSI string out of the original Unicode string, passes that to the API, then converts it back to Unicode. So a new StringW type, even as an alias, would be very confusing... it would mean 'An identical string, which when used in APIs disables ANSI<->Unicode conversion'.... I think In WinDevLib (formerly tbShellLib), most APIs are provided as a set: Public Declare PtrSafe Function AbortSystemShutdownA Lib "advapi32" (ByVal lpMachineName As String) As BOOL
Public Declare PtrSafe Function AbortSystemShutdownW Lib "advapi32" (ByVal lpMachineName As LongPtr) As BOOL
Public DeclareWide PtrSafe Function AbortSystemShutdown Lib "advapi32" Alias "AbortSystemShutdownW" (ByVal lpMachineName As String) As BOOL Though for some areas, I've been forgoing the ANSI version, since it's really bad practice to be writing new code with them, and the |
Beta Was this translation helpful? Give feedback.
-
More of a question than a feature request. Just wondered what the logic was behind using the
DeclareWide
syntax vs having a seperate type for unicode/ascii strings (withString
still being supported but non-explicit) in DLLs. I.E.Instead of this:
Why wasn't something like this chosen:
?
I ask mainly because I believe introduction of
PtrSafe
by microsoft was a mistake and lead to loads of unnecessary conditional compilation. And although I can't see why this change would lead to a bunch of required conditional compilcation necessarily it kinda feels like the same sort of thing and a better option would be type aliases... I.E.Maybe I'm wrong though, and there is more of a need for seperate definitions.
Beta Was this translation helpful? Give feedback.
All reactions