The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Maeser on February 26, 2006, 09:09:26 AM

Title: Really Simple question
Post by: Maeser on February 26, 2006, 09:09:26 AM
Hey guys

I've been trying to figure this out for a couple of hours

I've started converting my projects to using String tables, just to simplify changing of dialog strings, etc. But I just need to know how to do one thing..make a variable to hold the address of the string in memory...like

.data?
var [either db ? or handle ? I'm not sure]

.code
...
invoke LoadString, hInst, MB_FULLSCREENQUESTION, Addr buffer, 256


Now buffer gets filled up with the data...which is fine...but ECX gets the address of the string in the resource table. I need to assign the address to the handle. It should be ok since its 0 terminated, right? If not...how would I allocate a buffer to said handle...

I know this is really easy...but I'm tired and can't seem to wrap my head around it..
Title: Re: Really Simple question
Post by: hutch-- on February 26, 2006, 10:23:04 AM
Maeser,

As long as you only need the data within the scope of a procedure, you create a LOCAL buffer.


LOCAL buffer[128]:BYTE


You address it either with the ADDR operator in MASM or you can load the address by its name into a register with LEA.


lea eax, buffer


If you need GLOBAL scope, you create the data space in either the initialised data section if its static text or in the uninitialised data section if you just want space.


.data
  mytxt db "This is my text", 0

  ; or

.data?
  mybuffer db 128 dup (?)


You directly address a buffer of this type using OFFSET in code like,


mov eax, OFFSET mybuffer
Title: Re: Really Simple question
Post by: ThoughtCriminal on February 26, 2006, 11:54:46 AM


stringptr dd string1

string1 db "Hello whirled",0

or  for a table:

stringptr:
dd string1
dd string2
dd string3
etc.

stringptr equals the staing at offset 0, the naxt string is at stringptr+4, stringptr+8, etc.
Title: Re: Really Simple question
Post by: Maeser on February 26, 2006, 07:30:08 PM
Heh. Thanks guys. But uhh...one small problem.

I kind of want it like this..

nameofpointer dd ? (or whatever)

so when I call LoadString (Ecx gets filled with a nice addresse)

I can just go

mov nameofpointer, Ecx

and nameofpointer will hold the resource String's addresse. However, when I try it in my code...nameofpoiner still points to the same place in memory and it now contains a few characters of garbage
Title: Re: Really Simple question
Post by: PBrennick on February 26, 2006, 08:12:56 PM
.data
  mytxt db "This is my text", 0   ;  This is all that is necessary

  ; and

.data?
  nameofpointer  dd  ?  ;  This is really unnecessary as you can use eax in your function callls such as LoadString


.code
;... some code probably
mov eax, offset mytext
mov nameofpointer, eax    ;  This is really unnecessary as you can use eax in your function callls such as LoadString


Paul

Title: Re: Really Simple question
Post by: Maeser on February 26, 2006, 08:20:37 PM
That isn't quite what I meant...there isn't any
.data
  mytxt db "This is my text", 0   ;  This is all that is necessary


It's a string from the string table resource.
I'm looking for some like this:
.data?
  nameofpointer  dd  ?  ;

Just the pointer. nothing else.

then when I call LoadString, how would I go about moving the address in ECX into the pointer?
Title: Re: Really Simple question
Post by: Maeser on February 26, 2006, 08:54:55 PM
I'm looking for something similar to the C++:
char *var = null;

... //code

var = Ecx; //Mix of asm and C++, but whatever. basically re-assigning the pointer to whatever was in ECX
Title: Re: Really Simple question
Post by: Maeser on February 26, 2006, 09:34:54 PM
Ok Nevermind. I'm just an idiot. My debugger was displaying the pointer's content as ASCII, rather than hex.

Sorry to all
Title: Re: Really Simple question
Post by: Mincho Georgiev on February 26, 2006, 09:41:01 PM
char *c it means piointer to that char , and logically , the c+1 is pointer to the next char ,e.t.c. In other words, you need a pointer to an array with a fixed(known) size. If the size is bigger than 64 KB, you need a dinamically reserved memory (reserved ,depending of the free memory on that time).
What i'm trying to say is that you need to allocate a part of memory to get a pointer to that part and fill it with some bytes. In 'C' that is malloc function.
Here we use mutch more often API functions for that, by example GlobalAlloc   respectiveli  LocalAlloc to get that esteemed pointer.
Then you get a pointer to the first byte of the allocated memory.
Excuse me if you didn't get what i mean ,but i had visit a birthday tonight and drink a couple of vodka's  :bg
Title: Re: Really Simple question
Post by: PBrennick on February 26, 2006, 09:59:16 PM
Maeser,
Don't worry about it.  We are all an idiot every now and then.  It keeps us sane.  Heck, I was an idiot just yesterday.

Shaka, go to bed, you are drunk. :toothy

Paul
Title: Re: Really Simple question
Post by: Maeser on February 26, 2006, 11:28:48 PM
Okay so it seems my problem isn't quite solved. But I have frakked around with it some more, to no avail. Here's what I have (Header excluded because IDE sticks it in for me):
GetString Proto :UINT
.Const

.Data?
hInstance   HANDLE ?
Testc DD ?
buffer DB 256 Dup (?)

.Data

.Code

start:
Invoke GetModuleHandle, NULL
Mov hInstance, Eax
Invoke GetString, MB_FULLSCREENQUESTION
Invoke ExitProcess, 0
Ret

GetString Proc uId:UINT
.If hInstance == NULL
Ret
.Else
Invoke LoadString, hInstance, uId, Addr buffer, SizeOf buffer
Invoke GlobalAlloc, GPTR, Eax
Mov Testc, Eax
.EndIf
Ret
GetString EndP

End start


So. Here it is. What I would like, is that instead of filling Testc with the address from EAX, I want it to start pointing at the newly allocated memory. Or am I just thinking too high level?
Title: Re: Really Simple question
Post by: PBrennick on February 27, 2006, 12:36:53 AM
For a 256 byte string this is overkill, why not tell us what you are actually trying to do because you are (kindly said) shooting in the dark.

Paul

Title: Re: Really Simple question
Post by: Maeser on February 27, 2006, 12:43:14 AM
Uhhh....what?
Title: Re: Really Simple question
Post by: PBrennick on February 27, 2006, 12:46:31 AM
For a 256 byte string this is overkill, why not tell us what you are actually trying to do because you are (kindly said) shooting in the dark.

EDIT: you saw me change my thoughts, sorry, this is correct and so is the above.

Paul
Title: Re: Really Simple question
Post by: Maeser on February 27, 2006, 12:53:30 AM
256 is just a buffer because each string in the String table is a different size. what I do is load the string, allocate a space with the exact number of bytes, then I want the pointer to point to the newly allocated space, which I will fill with my string
Title: Re: Really Simple question
Post by: ThoughtCriminal on February 27, 2006, 06:50:32 AM
How about this....

.data
_0 dd SIZEOF err1
_4 dd err1
_8 dd SIZEOF err2
_12 dd err2
_16 dd SIZEOF err3
_20 dd err3

err1 db "Error 1",0
err2 db "Error 2",0
err3 db "Error 3",0