News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetParentFolder

Started by jdoe, April 28, 2006, 05:02:12 AM

Previous topic - Next topic

jdoe

I'm playing with ANSI to Unicode procedures conversion. When I started to do this one, all goes fine but Unicode strings can be big or little endian. How can I make this procedure to take care of both.


;
; Return TRUE if successful
;
GetParentFolderW proc p_lpBuffer:dword, p_lpszPath:dword

   invoke StrCpyW, p_lpBuffer, p_lpszPath
   cmp eax, 3   ;
   ja @F        ; drives have no parent "C:\"

   xor eax, eax
   ret

@@:
   mov edx, p_lpBuffer
   shl eax, 1
   sub eax, 2              ; exclude last char in case it is a backslash

   align 4
@@:
   sub eax, 2
   jz @F
   cmp word ptr [edx+eax], 5Ch   ; "\"    <--- or could be 5C00h
   jne @B

   mov word ptr [edx+eax+2], 0

   mov eax, TRUE

@@:
   ret

GetParentFolderW endp


Any idea ?

asmfan

Jdoe, if we certainly know that we process unicode string you can try to add 2 bytes of a char (assuming that one is zero for sure) and then compare to a certain byte that refers to a backslash...
Add   hi, lo
Cmp  hi, backslash
Russia is a weird place

Mincho Georgiev

Hi, jdoe, The next one is a code snippet - this is the method that i use for converting both big and little endian, just a snippet, but
is from one of my programs and it's work fine. Take a look and ask anything if you like to, because the comments really can be better written than that.



[attachment deleted by admin]

jdoe

Thanks for your inputs guys but the solution for this appears to me to be very simple now.

GetParentFolder need a path so the third character must be a backslash. If I read this backslash into cx, I can replace the compare with 5Ch (in the loop) with cx without bother about little and big endian.   :wink


Mincho Georgiev

I post the snippet above not to resolve your current problem, jdoe. It just shows how to resolve the BE/LE from and to ANSI problems in uicode conversion.
And by the way, they're alot. You can be sure, and you will ,while  stepping throught the theme.
Greets!

jdoe

Quote from: shaka_zulu on April 28, 2006, 10:06:26 PM
I post the snippet above not to resolve your current problem, jdoe. It just shows how to resolve the BE/LE from and to ANSI problems in uicode conversion.
And by the way, they're alot. You can be sure, and you will ,while  stepping throught the theme.
Greets!

Be sure I'll keep them for futur use. I know I'm going to need that kind of snippet one day. Just a question of days... or hours !!!  :wink

I have about 50 VB functions to convert to MASM. Functions I have used for years and while I'm doing this conversion, I'm learning a lot. After two years of being bored with VB, I really got a new enjoyment about programming when I started MASM. I think I never been more satisfied about the code I've wrote. The project I'm working on rigth now is an improved version of a VB program I did many months ago (called CAB Tool, which is starting to be popular with RyanVM XP updates pack and on MSFN forum) and I can't wait to have a first beta.

This board is very friendly and I will always give credits to it in all my projects.  :clap:
I hope to have enough knowledge one day to help people like reading posts on this board was helpful for me.

I wish long life to hutch and his board.