|
Prev: HLA wont compile!!
Next: New to asm world!
From: Gary K on 5 Oct 2005 02:23 Greetings & Salutations, Feel free to join in if you know the words :) 1) mov wc.lpszClassName,OFFSET ClassName 2) mov lf.lfFaceName,OFFSET FontFace For those of you that don't recognize the above structures, lf is a LOGFONT structure, and wc is the WNDCLASSEX structure. Both structures are declared LOCAL in a PROC block. FontFace & ClassName are defined in the .data block. The surrounding code is similar, instructions above fill in the rest of the structure, instruction below invokes the windows API function (CreateFontIndirect & RegisterClassEx). #1 works, #2 does not and gives the following error message "error A2070: invalid instruction operands". What's the difference?
From: Betov on 5 Oct 2005 04:38 Gary K <> ?crivait news:2tr6k19ll5lgopcmoj4jpg2u7p1qa4jhpn(a)4ax.com: > Greetings & Salutations, > > Feel free to join in if you know the words :) > > 1) mov wc.lpszClassName,OFFSET ClassName > 2) mov lf.lfFaceName,OFFSET FontFace > > #1 works, #2 does not and gives the following error message "error > A2070: invalid instruction operands". What's the difference? There are 3 errors at a time: 1) You are using MASM, whereas plenty of good an real Assemblers are available around. 2) MASM Syntax is heavily faultive and confusing, and you are just doing the demonstration of it. 3) The FaceName Member of a Font Structure is a String, not a Pointer to a String. The length of this Field is LF_FACESIZE (020h). Betov. < http://rosasm.org >
From: hutch-- on 5 Oct 2005 06:48 Gary, An OFFSET in MASM is literally a location in a binary file, almost exclusively a data label and it is known at assembly time. What you have attempted will not work as the structure has a 32 byte buffer at lfFaceName that requires the string containing the name to be written at the address. WIN32.HLP lfFaceName ---------- A null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters, including the null terminator. The EnumFontFamilies function can be used to enumerate the typeface names of all currently available fonts. If lfFaceName is an empty string, GDI uses the first font that matches the other specified attributes. What you need to have is the font name you require as a zero terminated string and copy that font name to the 32 byte buffer in the structure including the zero terminator. Any zero terminated string byte copy algo will do that for you. The error message you are getting is from trying to copy a memory operand to another memory operand. Regards, hutch at movsd dot com
From: hutch-- on 5 Oct 2005 07:38 Gary, Here is a working example. .data? hFont dd ? ------------------------------------- LOCAL lf :LOGFONT LOCAL hOld :DWORD LOCAL hDC :DWORD LOCAL rct :RECT Case WM_INITDIALOG mov lf.lfHeight, 16 mov lf.lfWidth, 8 mov lf.lfEscapement, 0 mov lf.lfOrientation, 0 mov lf.lfWeight, 400 mov lf.lfItalic, 0 mov lf.lfUnderline, 0 mov lf.lfStrikeOut, 0 mov lf.lfCharSet, DEFAULT_CHARSET mov lf.lfOutPrecision, OUT_DEFAULT_PRECIS mov lf.lfClipPrecision, CLIP_DEFAULT_PRECIS mov lf.lfQuality, PROOF_QUALITY mov lf.lfPitchAndFamily,DEFAULT_PITCH .data fname db "times new roman",0 .code push esi push edi ; ------------------------------- ; copy string to structure member ; ------------------------------- mov esi, OFFSET fname lea edi, lf.lfFaceName mov ecx, LENGTHOF fname rep movsb pop edi pop esi invoke CreateFontIndirect,ADDR lf mov hFont, eax Case WM_PAINT invoke GetDC,hWin mov hDC, eax invoke SelectObject,hDC,hFont mov hOld, eax invoke SetBkMode,hDC,TRANSPARENT mov rct.left, 10 mov rct.top, 30 mov rct.right, 200 mov rct.bottom, 45 fn DrawText,hDC,"Times New Roman",-1,ADDR rct,DT_VCENTER or DT_CENTER invoke DeleteObject,hFont invoke SelectObject,hDC,hOld invoke ReleaseDC,hWin,hDC ------------------------------------- Regards, hutch at movsd dot com
From: Betov on 5 Oct 2005 08:16
"hutch--" <hutch(a)movsd.com> ?crivait news:1128512658.831439.47860 @g43g2000cwa.googlegroups.com: > smile, > >> As opposed to the actual Syntax Standards. > > MASM is the industry standard. Maybe the guys would prefer logic and quality to industry. :) >> Which would be completely absurd, as long as, in true Assembly, >> there would no need of any Copy execution, for a String that is >> known at write time. > > This is not always the case, many fonts are selected at runtime from a > common dialog box. I will let... Fodder, our prefered C programmer, answer to this definitive absurdity, as long as he is quite good at explaining to the amaized people, how the Win32 Functions work, and what they do, - what you seem to completely fail to understand, here -, and as long as i have several interresting other things to do, for now... :) Betov. < http://rosasm.org > |