Pseudo string types and zero

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Pseudo string types and zero

Post by mback2k »

It would be cool if .p-ascii, .p-utf8 and .p-unicode could also accept zero as argument. This would help a lot with Windows API functions that either accept a string or zero.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes I have encountered that a couple of times now; there are indeed occasions when I would like to pass a null string and not an empty one. Unfortunately, it would appear that #Null$ equates to an empty string and not a null one.

+1. :)
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Maybe this helps?

Code: Select all

Procedure GetRawString(N.i)
  If N = 0
    Debug "Null string"
  Else
    Debug PeekS(N)
  EndIf
EndProcedure

a.s
CallFunctionFast(@GetRawString(), a)
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post by mback2k »

Trond, I don't understand what the purpose of this code snippet is.

I don't want to use it with CallFunction or Prototypes, I am using many WinAPI libraries with Import and it's a little bit annoying to always do the ASCII->Unicode and back convertion on my own, because sometimes I need to pass a string to one function and another time I need to pass a zero as argument to the same function at the same parameter index.

Edit: Now I see what you mean, but that way I can't use benefit .p-types.
Last edited by mback2k on Sun Jan 11, 2009 3:15 pm, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It shows that if you pass a non-initialized string variable, then it's like passing a null string.
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post by mback2k »

Yes, but always creating a dummy string variable before calling a function seems to be a little bit unconventional. IMHO.

Pseudotypes have a purpose and they work very well. They just need to be tweaked a little.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Aye Trond has a good point there. Now why the hell did I not think of that before? Ack, must be getting old! :)

Still, it would be more explicit in a way if the pseudotypes could just accept an explicit zero.
I may look like a mule, but I'm not a complete ass.
Post Reply