Page 1 of 1

Invalid memory access x64

Posted: Tue Dec 31, 2013 9:03 pm
by spacebuddy
I have this procedure

Procedure.S ConvertCFStringIntoString(CFStringRef)
Protected String.s = Space(256)
If CFStringRef
CFStringGetCString(CFStringRef, @String, Len(string), 0) <--- Invalid memory access
EndIf
ProcedureReturn Trim(String)
EndProcedure

I only get this error when I compile to x64, it works in x86?

Anyone know why it would not work in 64-bit mode?

Thanks All :D

Re: Invalid memory access x64

Posted: Tue Feb 04, 2014 4:27 am
by Maitre_Kanter
Hello,

what's happen if you use CFStringGetCStringPtr

Code: Select all

ImportC ""
  CFStringGetSystemEncoding()
  CFStringGetLength(CFStringRef.I)
  CFDictionaryGetCount(DictionaryRef.L)
  CFDictionaryGetKeysAndValues(DictionaryRef.L, *Keys, *Values)
  CFRelease(CFType.I)
  CFStringGetCString(CFStringRef.I, *StringBuffer, BufferSize.I, CFStringEncoding.L)
  CFStringGetCStringPtr(CFStringRef.I, CFStringEncoding.L)
  CFURLCreateWithFileSystemPath(AllocatorRef.I, CFStringFilePath.I, PathStyle.I, IsDirectory.I)
EndImport


Procedure.S ConvertCFStringIntoString(CFStringRef)
    Protected String.S
    Protected *ptr_converted_str
    Protected encodingmethod = CFStringGetSystemEncoding()
    
    Debug CFStringGetLength(CFStringRef)
    
    If CFStringRef
        *ptr_converted_str = CFStringGetCStringPtr(CFStringRef, encodingmethod )
        Debug MemoryStringLength(*ptr_converted_str) ; for checking if 256 is big enough
        ;your stuff
        String = PeekS( *ptr_converted_str )
    EndIf
    ProcedureReturn Trim(String)
    
EndProcedure