Crash in Unicode mode only [SOLVED]
Posted: Wed Oct 07, 2015 2:50 pm
I am tracking crashes in my program and very tired.
While program is very stable in nonUnicode it is crashing during memory operations.
It would be very good to see PB do this memory allocation itself instead of changing all code such way by adding 2 bytes to memoryallocation manually
While program is very stable in nonUnicode it is crashing during memory operations.
Code: Select all
Procedure.s EnumDevz()
; How to enumerate hardware devices by using SetupDi calls
; mskuma 26 June 2006
; adapted from http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q259695
; (Windows only)
TMPDevicez.s=""
Structure SP_DEVINFO_DATA
cbSize.l
ClassGuid.GUID
DevInst.l; // DEVINST handle
Reserved.l;
EndStructure
hDevInfo.l = 0
DeviceInfoData.SP_DEVINFO_DATA
i.l = 0
sepa.s="!!!"
;devicesList.s = ""
; Create a HDEVINFO with all present devices
hDevInfo = SetupDiGetClassDevs_(#Null,0, 0, #DIGCF_PRESENT | #DIGCF_ALLCLASSES)
If hDevInfo = #INVALID_HANDLE_VALUE
ProcedureReturn "0"
EndIf
; Enumerate through all devices in Set
DeviceInfoData\cbSize = SizeOf(SP_DEVINFO_DATA)
While SetupDiEnumDeviceInfo_(hDevInfo, i, @DeviceInfoData)
DataT.l
Protected *buffer = #Null
buffersize.l = 0
While Not SetupDiGetDeviceRegistryProperty_(hDevInfo,@DeviceInfoData,#SPDRP_DEVICEDESC,@DataT,*buffer,buffersize,@buffersize)
If (GetLastError_() = #ERROR_INSUFFICIENT_BUFFER)
; Allocate the buffer size, using twice the size to avoid problems on W2k MBCS systems per KB 888609
*buffer = AllocateMemory(buffersize*2) ;Crashes in this line
Else
; Insert error handling here
Break
EndIf
Wend
NexDev.s=PeekS(*buffer)
If FindString(TMPDevicez.s, NexDev.s, 1, #PB_String_NoCase)=0
TMPDevicez.s + sepa.s+NexDev.s ; just for checking
EndIf
If (*buffer)
FreeMemory(*buffer)
EndIf
i+1 ; increment to next device
Wend
; finish up
If ( GetLastError_() <> #NO_ERROR And GetLastError_() <> #ERROR_NO_MORE_ITEMS )
; Insert error handling here
ProcedureReturn "0"
EndIf
; Cleanup
SetupDiDestroyDeviceInfoList_(hDevInfo)
; ProcedureReturn MD5Fingerprint(@devicesList,Len(devicesList))
;Debug TMPDevicez.s
ProcedureReturn TMPDevicez.s
EndProcedure
; and
Procedure.s HashString(String2HASH.s)
String2HASHLen.l=Len(String2HASH.s)
If String2HASHLen>0
*MD5Buffer = AllocateMemory(String2HASHLen.l*1.5) ; Prepare a buffer with data
If *MD5Buffer
PokeS(*MD5Buffer, String2HASH.s) ; Here also crashes
Length = MemoryStringLength(*MD5Buffer)
If String2HASHLen<>Length
ReAllocateMemory(*MD5Buffer,Length*1.5)
EndIf
If ExamineMD5Fingerprint(1) ; start the calculation
MD5$ = MD5Fingerprint(*MD5Buffer, Length) ; compare to a calculation in 1 step
EndIf
FreeMemory(*MD5Buffer)
EndIf
EndIf
ProcedureReturn MD5$
EndProcedure