Declare Function Ustr2Wstr(sss As String) As String
Function Ustr2Wstr(sss As String) As String
sss = sss & chr(0) & chr(0)
Dim As Wstring * 500 aux = ""
asm pushad
asm mov esi, [sss]
asm lea edi, [aux]
asm mov ecx, 500
asm rep movsb
asm popad
Return aux
End Function
The lines from 'sss ...' to 'asm popad' work perfectly if used directly in the code, buth the function fails. Can this be repaired?
I assume "the function fails" means the code builds without error messages but doesn't work, i.e. crashes or produces wrong results. Try being precise in the description of the problems encountered.
Remember the assembly code is a hack: The rep movsb just copies bytes from one memory location to another. The problem with your function here is another one, though: You return a local string variable. That can't work because in the moment when you leave the function, that local memory area (on the stack) is no longer valid. Strange that the compiler does not throw an error, though.
Btw it might be better if you keep your questions in one "personal" thread; otherwise the forum will get very cluttered with tiny threads like this.
Yes, fails means no usable aux returned; no crash and no error message. OK, the reason must be associated to the assembly code hack, although I don't understand why aux can not be returned... But the use of a function was just an attempt, I don't need it really. (I assumed this was a basic newbie issue refering to functions, so the new thread was more meaningful.)
Btw, I am making huge progress in my project thanks to your help. (The breakthrough was 'instr(stg, chr(58) & chr(0))' instead of failing 'instr(stg, ":" & chr(0))', and of course your tricky unicodestring2wstring method.)
jj2007 wrote:You return a local string variable. That can't work because in the moment when you leave the function, that local memory area (on the stack) is no longer valid.
I am probably wrong on this: Disassembly shows that the "local" string variable gets malloc'ed. Test case: