The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: jdoe on April 28, 2006, 05:02:12 AM

Title: GetParentFolder
Post by: jdoe on April 28, 2006, 05:02:12 AM
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 ?
Title: Re: GetParentFolder
Post by: asmfan on April 28, 2006, 05:52:51 AM
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
Title: Re: GetParentFolder
Post by: Mincho Georgiev on April 28, 2006, 11:24:55 AM
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]
Title: Re: GetParentFolder
Post by: jdoe on April 28, 2006, 09:26:44 PM
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

Title: Re: GetParentFolder
Post by: Mincho Georgiev 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!
Title: Re: GetParentFolder
Post by: jdoe on April 28, 2006, 11:55:22 PM
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.