[Windows] AutoComplete for StringGadgets

Share your advanced PureBasic knowledge/code with the community.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Karbon - it'd take me about an hour or two to fix up (read: update horribly old code) my autocomplete routines if you want me to do it.

<Xombie slowly sneaks out of freak's thread>
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Just heard back. 5 reports already of the crash with the new memory lib... I asked them to report the contents of the message requester (to see if the heap invalid message is displaying) but no one has said that they saw it. That shouldn't be taken to mean that no one did, people are pretty notorious for not reporting that stuff.

I'll send it to a few people specifically and see if they can tell me if the heap invalid message is shown.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Hey Xombie -- I actually like the API's flexibility in the different styles it supports but I can't use it if it keeps crashing without explanation.

If I can't get this moving in the next couple of days I'll have to switch!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It could also be that the actual AllocateMemory() is overwritten by some garbage.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Just heard back.. The crash happens and does *not* display the heap invalid error, so according to that code you sent it's valid..

Crazy, eh?

See... A few thousand users can break anything! :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I just realized i made a mistake with the heap validation.
The AllocateMemory() command actually has its separate heap from the one used
by the other PB libraries (which makes sense). So we were testing the wrong one.

Here we go again:
This one tests the heap used for string storage, the one
from AllocateMemory(), and the one for the PB libraries

Code: Select all

Procedure ValidatePBHeap(LineNumber)
  Protected StringHeap, MemoryHeap, InternalHeap
  
  !extrn _PB_Memory_Heap
  !extrn _PB_StringHeap
  
  !mov eax, dword [_PB_MemoryBase]
  !mov [p.v_InternalHeap], eax
  !mov eax, dword [_PB_StringHeap]
  !mov [p.v_StringHeap], eax
  !mov eax, dword [_PB_Memory_Heap]
  !mov [p.v_MemoryHeap], eax    
  
  If HeapValidate_(StringHeap, 0, 0) = 0
    MessageRequester("Error", "String Heap invalid at Line: "+Str(LineNumber))
  EndIf    
  If HeapValidate_(MemoryHeap, 0, 0) = 0
    MessageRequester("Error", "Memory Heap invalid at Line: "+Str(LineNumber))
  EndIf   
  If HeapValidate_(InternalHeap, 0, 0) = 0
    MessageRequester("Error", "Internal Memory Heap invalid at Line: "+Str(LineNumber))
  EndIf 
EndProcedure

Macro _validate
  ValidatePBHeap(#PB_Compiler_Line)
EndMacro
Please test it again.
quidquid Latine dictum sit altum videtur
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Got it and just sent it out... I should hear something back in a few hours..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Wow, sure enough, I can reproduce it on another Windows XP Pro computer here..

Code: Select all

Procedure New_EnumString(StringArray$(1), StringCount)
  *THIS.EnumString = 0
  
  Size = 4 + StringCount * 4
  For i = 0 To StringCount-1
    Size + Len(StringArray$(i)) * 2 + 2
  Next i
  
  _validate ; THIS REPORTS INVALID HEAP AND CRASHES RIGHT AFTER
  
  *StringBuffer.EnumStringBuffer = AllocateMemory(Size)
  If *StringBuffer
    *StringBuffer\RefCount = 1
    *Pointer = *StringBuffer + 4 + StringCount * 4
    
    For i = 0 To StringCount - 1     
      *StringBuffer\Strings[i] = *Pointer 
      PokeS(*Pointer, StringArray$(i), -1, #PB_Unicode)
      *Pointer + Len(StringArray$(i)) * 2 + 2
    Next i
    
    _validate
    
    *THIS = AllocateMemory(SizeOf(EnumString))
    If *THIS
      *THIS\Vtbl        = ?IEnumStringVtbl
      *THIS\RefCount    = 1
      *THIS\StringCount = StringCount
      *THIS\Enumerator  = 0
      *THIS\Buffer      = *StringBuffer
    Else
      FreeMemory(*StringBuffer)
    EndIf
  EndIf   
  
  ProcedureReturn *THIS
EndProcedure
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Atleast a step in the right direction... :)

Now the problem must be somewhere before this line is reached.
Some pointer stuff, PokeS() or other memory access must be going wrong.

You'll just have to throw some _validate lines around the code to find out where.

(I just hope its not in my code :))
quidquid Latine dictum sit altum videtur
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Found it.

Looks like this isn't very unicode friendly.. I'll give it a go at re-writing it.

Code: Select all

Procedure.l AddODBCConnection(Driver$,Attributes$)
  While Right(Attributes$,2)<>";;"
    Attributes$+";"
  Wend
  
  _validate
  
  *LPAttribMem=AllocateMemory(Len(Attributes$)*SizeOf(CHARACTER))
  
  _validate
  
  PokeS(*LPAttribMem,Attributes$,Len(Attributes$))
  
  _validate ; < - INVALID HERE
  
  For l=1 To Len(Attributes$)
    CompilerIf #PB_Compiler_Unicode
    If PeekW(*LPAttribMem + (l-1) * SizeOf(CHARACTER))=Asc(";")
      PokeW(*LPAttribMem + (l-1) * SizeOf(CHARACTER),0)
    EndIf
    CompilerElse
    If PeekB(*LPAttribMem + l -1)=Asc(";")
      PokeB(*LPAttribMem + l -1,0)
    EndIf
    CompilerEndIf
  Next
  
  _validate
  
  result=SQLConfigDataSource_(0,#ODBC_ADD_DSN,Driver$,*LPAttribMem)
  
  FreeMemory(*LPAttribMem)
  
  ProcedureReturn result
  
EndProcedure
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You are not allocating enough space for *LPAttribMem
PokeS() also writes the ending NULL, so you need (Len(Attributes$)+1)*SizeOf(CHARACTER) bytes of space.
quidquid Latine dictum sit altum videtur
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Wow! Forest for the trees on that one.

THANK YOU!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yea, I never knew it was updated since you just hit "edit" instead of "reply" :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

is it possible to have diff gadgets with different arrays with autocomplete at the same time?

And how do you add items to list while program is running?
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Post Reply