In C++, we can use: char *szStr; //some codes here szStr=new char ; //other codes here delete [] szStr; How can I do this with Win32ASM?
Posted on 2000-12-04 12:47:00 by beginner
you have to use GlobalAlloc and GlobalFree look at your api reference to learn how to use it
Posted on 2000-12-04 13:28:00 by (scalp)
In fact, I know how to use these APIs. What I actually want to know is, is there a way to make it as easy as that in C++? (using new/delete) Anyway, thanks for your help. :)
Posted on 2000-12-04 14:13:00 by beginner
"Dynamic" array is another illusion created by compilers. They handle it transparently for you. If you use assembly language, there is no such native facility for you. You have to implement it yourself.
Posted on 2000-12-04 18:49:00 by Iczelion
And actually, a better system than GloablAlloc would be HeapAlloc/HeapReAlloc. Then the memory is fixed (unlike GlobalAlloc which Windows has the freedom to move as it sees it), and can be created and removed with less problems than GlobalAlloc.
Posted on 2000-12-04 20:50:00 by Racso
Using the ole bstr functions comes close. James ; ######################################################################### .386 .model flat, stdcall option casemap :none ; case sensitive ; ######################################################################### include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\oleaut32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\oleaut32.lib ; ######################################################################### ;--------------------------------------------------------------------------- NewBStr MACRO BstrName, Text:VARARG LOCAL lbl LOCAL szTemp jmp lbl szTemp db Text,0 lbl: INVOKE SysAllocStringByteLen,ADDR szTemp,@SizeStr(szTemp)+1 mov BstrName,eax ENDM ;--------------------------------------------------------------------------- FreeBStr MACRO BstrName INVOKE SysFreeString,BstrName ENDM ;------------------------------------------------------------------------------ ReAsgnBstr MACRO BstrName, Text:VARARG LOCAL lbl LOCAL szTemp jmp lbl szTemp db Text,0 lbl: INVOKE SysReAllocString, ADDR BstrName, ADDR szTemp ENDM ;--------------------------------------------------------------------------- .data sTemp DWORD 0 .code start: NewBStr sTemp,"James" INVOKE MessageBox,0, sTemp ,sTemp,MB_OK ReAsgnBstr sTemp,"James C. Fuller" INVOKE MessageBox,0, sTemp ,sTemp,MB_OK FreeBStr sTemp INVOKE ExitProcess,0 end start
Posted on 2000-12-06 10:29:00 by jcfuller