The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Ic3D4ne on April 29, 2005, 08:51:12 PM

Title: Passing strings to procedures.
Post by: Ic3D4ne on April 29, 2005, 08:51:12 PM
I'm writing a "Leet-speak" converter using a GUI ( I know it's kind of lame, but it's intended to refresh my coding a bit)
And I'm having trouble passing strings.

The procedure takes in a DWORD argument, and I pass the "ADDR String" to it. It assembles fine, and I haven't found any faults in the code, but still the string remains untouched after it has been passed through the PROC.

Can ADDR and such directives not be used inside of procs?

All help greatly appreciated.

-Ic3D4ne
Title: Re: Passing strings to procedures.
Post by: Mark Jones on April 29, 2005, 10:00:45 PM
Hello Ic3D4ne. Have you read ASMINTRO.HLP? Strings are a big misnomer in assember; there are only register/memory/stack pointers and values. ADDR "string" is the same thing as saying "use this memory pointer's VALUE." Does it pass a valid offset to the string in memory at runtime? If so, then the conversion proc must not be converting properly, or it is saving to a different string location. Can you post the full code?

A different (easier?) approach may be to implement two LocalAlloc buffers. Say the application has three controls, a "do it" button, and "text input" & "leet speek output" edit controls. When the "do it" button is pressed, perform the following:

1. Get length of edit1's contents.
2. GlobalAlloc buffer 1, size of edit1 contents + 100 (use GPTR as alloc type for both)
3. GlobalAlloc buffer 2, size of edit1 contents + 100 (oversized just to be safe)
4. Copy edit1 contents into GlobalAlloc1.
5. Pass the handles of GlobalAlloc1 and GlobalAlloc2 to the conversion procedure.
6. In the conversion procedure, read bytes from GlobalAlloc1(+n) and output "leet" bytes to GlobalAlloc2(+n).
7. Set the second edit control's contents to ADDR GlobalAlloc2 - the converted text will appear in it.
Title: Re: Passing strings to procedures.
Post by: thomasantony on April 30, 2005, 02:00:10 AM
Hi,
An even more l33t way of doing it will be without a 'do it ' button. You can change the chars by processing WM_COMMAND message from the edit control each time a character is typed in the edit control. I don't think this works in dialog boxes(only in windows). In dialogs you can subclass the editr control.  Change the leet text on-the-fly with the typing of each char in the WM_COMMAND processing.

Thomas :U
Title: Re: Passing strings to procedures.
Post by: hutch-- on April 30, 2005, 03:45:03 AM
IceDane,

You would normally do a "l3Et0" conversion using a lookup table of 256 characters and either XLATB or manually swap the bytes to get when you are after. It is in fact an easy task to do once you understand character data.