News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Loading information from .ini to edit boxes

Started by timertik, March 21, 2007, 04:02:32 AM

Previous topic - Next topic

timertik

I need to load and save information to an .ini file so what ever is in line one of the .ini file is in editbox1 and so fourth for editbox2
I though I found my answer in the masm32 examples it was exactly what I was looking for but I got errors when assembling the code

here are the pieces I took out and added to my code
;include
include windows.inc
include user32.inc
include         masm32.inc
include kernel32.inc
include comctl32.inc
include         macros.asm
include         shell32.inc
include         gdi32.inc
include         gdi32.inc
include         winmm.inc

;include lib
includelib user32.lib
includelib kernel32.lib
includelib comctl32.lib
includelib user32.lib
includelib kernel32.lib
includelib comctl32.lib
includelib      shell32.lib
includelib      gdi32.lib
includelib      gdi32.lib
includelib      winmm.lib
includelib      masm32.lib
includelib      oleaut32.lib
.data?
      hEdit1    dd ?
      hEdit2    dd ?

         LOCAL pMem  :DWORD
         LOCAL flen  :DWORD
         LOCAL rpos  :DWORD
         LOCAL wpos  :DWORD
         LOCAL buffer[128]:BYTE
.elseif eax == WM_INITDIALOG
      ; get the handles for the edit controls
      ; -------------------------------------
        mov hEdit1, FUNC(GetDlgItem,hWin,1007)
        mov hEdit2, FUNC(GetDlgItem,hWin,1012)
        mov pMem, InputFile("getini.ini")   ; load the INI file into memory
        mov rpos, 0                         ; zero the read position pointer
        ; ------------------------------------------------------
      ; read each line of text and write it to an edit control
      ; ------------------------------------------------------
        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit1,WM_SETTEXT,0,ADDR buffer

        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit2,WM_SETTEXT,0,ADDR buffer
        free pMem                           ; free the memory
.elseif eax == WM_COMMAND
mov eax,wParam
mov pMem, alloc(4096)           ; allocate a buffer for the INI data
            mov wpos, 0                     ; zero the write position pointer

          ; --------------------------------------------------------------------
          ; write the contents sequentially from the edit controls to the buffer
          ; --------------------------------------------------------------------
            invoke GetWindowText,hEdit1,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)

            invoke GetWindowText,hEdit2,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)
            cmp OutputFile("getini.ini",pMem,len(pMem)), 0

            free pMem

here is the original code:
; ½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½

comment * --------------------------------------------
        A simple example of how to use the linein$ and
        lineout$ macros to read and write an INI file.
        In this example you can start this exe file,
        change the values in the INI file and save the
        changes to disk.
        -------------------------------------------- *

      .486                      ; create 32 bit code
      .model flat, stdcall      ; 32 bit memory model
      option casemap :none      ; case sensitive
 
;     include files
;     ~~~~~~~~~~~~~
      include \masm32\include\windows.inc
      include \masm32\include\masm32.inc
      include \masm32\include\gdi32.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\Comctl32.inc
      include \masm32\include\comdlg32.inc
      include \masm32\include\shell32.inc
      include \masm32\include\oleaut32.inc
      include \masm32\macros\macros.asm

;     libraries
;     ~~~~~~~~~
      includelib \masm32\lib\masm32.lib
      includelib \masm32\lib\gdi32.lib
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\Comctl32.lib
      includelib \masm32\lib\comdlg32.lib
      includelib \masm32\lib\shell32.lib
      includelib \masm32\lib\oleaut32.lib

      include \masm32\include\dialogs.inc

      DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

    .data?
      hWnd      dd ?
      hInstance dd ?
      hEdit1    dd ?
      hEdit2    dd ?
      hEdit3    dd ?
      hEdit4    dd ?
      hEdit5    dd ?

    .code

; ½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½

start:
 
      mov hInstance, FUNC(GetModuleHandle,NULL)

      call main

      invoke ExitProcess,eax

; ½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½

main proc

    Dialog "Load from INI File", \          ; caption
           "MS Sans Serif",10, \            ; font,pointsize
            WS_OVERLAPPED or \              ; styles for
            WS_SYSMENU or DS_CENTER, \      ; dialog window
            7, \                            ; number of controls
            50,50,155,105, \                ; x y co-ordinates
            1024                            ; memory buffer size

    DlgButton "Save",WS_TABSTOP,106,5,40,13,IDOK
    DlgButton "Close",WS_TABSTOP,106,20,40,13,IDCANCEL
    DlgEdit ES_LEFT or WS_BORDER or WS_TABSTOP,10,10,90,12,150
    DlgEdit ES_LEFT or WS_BORDER or WS_TABSTOP,10,25,90,12,151
    DlgEdit ES_LEFT or WS_BORDER or WS_TABSTOP,10,40,90,12,152
    DlgEdit ES_LEFT or WS_BORDER or WS_TABSTOP,10,55,90,12,153
    DlgEdit ES_LEFT or WS_BORDER or WS_TABSTOP,10,70,90,12,154

    CallModalDialog hInstance,0,DlgProc,NULL

    ret

main endp

; ½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½

DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    LOCAL pMem  :DWORD
    LOCAL flen  :DWORD
    LOCAL rpos  :DWORD
    LOCAL wpos  :DWORD
    LOCAL buffer[128]:BYTE

    Switch uMsg
      Case WM_INITDIALOG
        invoke SendMessage,hWin,WM_SETICON,1,
                           FUNC(LoadIcon,NULL,IDI_ASTERISK)
        m2m hWnd, hWin
      ; -------------------------------------
      ; get the handles for the edit controls
      ; -------------------------------------
        mov hEdit1, FUNC(GetDlgItem,hWin,150)
        mov hEdit2, FUNC(GetDlgItem,hWin,151)
        mov hEdit3, FUNC(GetDlgItem,hWin,152)
        mov hEdit4, FUNC(GetDlgItem,hWin,153)
        mov hEdit5, FUNC(GetDlgItem,hWin,154)

        mov pMem, InputFile("getini.ini")   ; load the INI file into memory
        mov rpos, 0                         ; zero the read position pointer

      ; ------------------------------------------------------
      ; read each line of text and write it to an edit control
      ; ------------------------------------------------------
        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit1,WM_SETTEXT,0,ADDR buffer

        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit2,WM_SETTEXT,0,ADDR buffer

        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit3,WM_SETTEXT,0,ADDR buffer

        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit4,WM_SETTEXT,0,ADDR buffer

        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit5,WM_SETTEXT,0,ADDR buffer

        free pMem                           ; free the memory

        return 1

      Case WM_COMMAND
        Switch wParam
          Case IDOK
            mov pMem, alloc(4096)           ; allocate a buffer for the INI data
            mov wpos, 0                     ; zero the write position pointer

          ; --------------------------------------------------------------------
          ; write the contents sequentially from the edit controls to the buffer
          ; --------------------------------------------------------------------
            invoke GetWindowText,hEdit1,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)

            invoke GetWindowText,hEdit2,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)

            invoke GetWindowText,hEdit3,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)

            invoke GetWindowText,hEdit4,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)

            invoke GetWindowText,hEdit5,ADDR buffer,128
            mov wpos, lineout$(ADDR buffer,pMem,wpos,0)

            cmp OutputFile("getini.ini",pMem,len(pMem)), 0

            free pMem

            jmp outa_here

          Case IDCANCEL
            outa_here:
            jmp quit_dialog
        EndSw
      Case WM_CLOSE
        quit_dialog:
         invoke EndDialog,hWin,0
    EndSw

    return 0

DlgProc endp

; ½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½

end start


this will not compile for me I have tried for hours even tried writing my own code for it but I failed
can someone help or provide a better example using 2 editboxes and an .ini file
I have been studying this example for so long my eyes hurt still with no progress
Im adding this to a large project maybe someone also knows a smaller example I dont want to have to sort through all the code again to find It doesnt even work  :dazzled:

thank you for reading this,

MichaelW

You are having problems assembling and linking the original example code? The original code assembles and links OK for me (and the result runs OK), whether I use the makeit.bat in the app directory, or use Build All from the project menu in QE. The code that you posted is not a complete source. To know what sort of problem you are having with it, we would need to see the complete source.
eschew obfuscation

timertik

the original code does not compile im using winasm to "Build all" and i get 28 errors
I dont know what could be wrong.

Assembling: C:\Users\Computer\Documents\Getini.asm
C:\Users\Computer\Documents\Getini.asm(114) : error A2006: undefined symbol : read_disk_file
InputFile(12): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(114): Main Line Code
C:\Users\Computer\Documents\Getini.asm(120) : error A2006: undefined symbol : readline
linein$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(120): Main Line Code
C:\Users\Computer\Documents\Getini.asm(123) : error A2006: undefined symbol : readline
linein$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(123): Main Line Code
C:\Users\Computer\Documents\Getini.asm(126) : error A2006: undefined symbol : readline
linein$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(126): Main Line Code
C:\Users\Computer\Documents\Getini.asm(129) : error A2006: undefined symbol : readline
linein$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(129): Main Line Code
C:\Users\Computer\Documents\Getini.asm(132) : error A2006: undefined symbol : readline
linein$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(132): Main Line Code
C:\Users\Computer\Documents\Getini.asm(149) : error A2006: undefined symbol : writeline
lineout$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(149): Main Line Code
C:\Users\Computer\Documents\Getini.asm(152) : error A2006: undefined symbol : writeline
lineout$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(152): Main Line Code
C:\Users\Computer\Documents\Getini.asm(155) : error A2006: undefined symbol : writeline
lineout$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(155): Main Line Code
C:\Users\Computer\Documents\Getini.asm(158) : error A2006: undefined symbol : writeline
lineout$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(158): Main Line Code
C:\Users\Computer\Documents\Getini.asm(161) : error A2006: undefined symbol : writeline
lineout$(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(161): Main Line Code
C:\Users\Computer\Documents\Getini.asm(163) : error A2006: undefined symbol : szLen
len(1): Macro Called From
  OutputFile(1): Macro Called From
   C:\Users\Computer\Documents\Getini.asm(163): Main Line Code
C:\Users\Computer\Documents\Getini.asm(163) : error A2006: undefined symbol : write_disk_file
OutputFile(1): Macro Called From
  C:\Users\Computer\Documents\Getini.asm(163): Main Line Code


I dont know why I would get these errors from an example these all seem to be solvable errors in many other cases but there is nothing wrong with the code

Example included below I cant get it to compile no matter what I do

[attachment deleted by admin]

MichaelW

I can duplicate those error messages by commenting out the "include \masm32\include\masm32.inc" statement. If the statement is not commented out in the source you are working with, then my first three guesses would be that someone accidentally deleted masm32.inc from the \masm32\include\ directory, or that your IDE, if you are using and IDE, for some reason cannot find the file, or that the MASM32 installation somehow failed to put it there. If it is not there, then you will need to reinstall MASM32, or convince someone to send the file to you. If it is there, and the length is not zero, then I have no idea what could be wrong.
eschew obfuscation

timertik

Here is my masm32.inc
although the last time I installed masm32 from the site It did not install any include files or lib files
I had to have someone else upload them for me Im using vista ultimate
I dont know if this masm32.inc is outdated or if something else is corrupt.
; #########################################################################
;
;                      Include file for MASM32.LIB
;
; #########################################################################

; for both --> arg num, buffer
ArgCl  PROTO :DWORD,:DWORD   ; GUI mode version
ArgClC PROTO :DWORD,:DWORD   ; console mode version

Alloc       PROTO :DWORD
Free        PROTO :DWORD

GetCL PROTO :DWORD,:DWORD

a2dw   PROTO :DWORD
atodw  PROTO :DWORD          ; return value in eax
htodw  PROTO :DWORD          ; return value in eax
dwtoa  PROTO :DWORD,:DWORD   ; value - buffer
dw2a   PROTO :DWORD,:DWORD
dw2hex PROTO :DWORD,:DWORD

GetErrDescription PROTO :DWORD

FloatToStr  proto stdcall fpin: QWORD, szDbl: PTR CHAR
FloatToStr2 proto stdcall fpin: QWORD, szDbl: PTR CHAR
StrToFloat proto stdcall szIn: PTR BYTE, fpout: PTR DWORD

InString  PROTO :DWORD,:DWORD,:DWORD ; StartPos - lpszString - lpszSubStr

BinSearch PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD      ; classic scanner

; Boyer Moore based algorithms
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BMBinSearch  PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD   ; complete BM
BMHBinsearch PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD   ; horspool variation
SBMBinSearch PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD   ; simplified version
WordCount    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

XorData PROTO :DWORD,:DWORD,:DWORD,:DWORD
RolData PROTO :DWORD,:DWORD,:DWORD,:DWORD
RorData PROTO :DWORD,:DWORD,:DWORD,:DWORD

lcase PROTO :DWORD          ; address string
ucase PROTO :DWORD          ; address string

ltrim PROTO :DWORD,:DWORD   ; source - dest
rtrim PROTO :DWORD,:DWORD   ; source - dest

trim PROTO :DWORD

lnstr  PROTO :DWORD          ; length in eax
StrLen PROTO :DWORD

revstr PROTO :DWORD,:DWORD

cmpsi PROTO :DWORD,:DWORD,:DWORD

; ---------------------------------------------------------------
; Note that these following 3 procedures are no longer included
; in the library, they have been replaced with later and faster
; procedures. Code written with these procedures is still
; functional by means of the following equates which map them
; directly to the later procedures.
; ---------------------------------------------------------------

; lstr   PROTO :DWORD,:DWORD,:DWORD    ; source - substring - length
; rstr   PROTO :DWORD,:DWORD,:DWORD    ; source - substring - length
; midstr PROTO :DWORD,:DWORD,:DWORD,:DWORD

szCatStr PROTO :DWORD,:DWORD
szLeft   PROTO :DWORD,:DWORD,:DWORD
szRight  PROTO :DWORD,:DWORD,:DWORD
szMid    PROTO :DWORD,:DWORD,:DWORD,:DWORD
szMultiCat PROTO C :DWORD,:DWORD,:VARARG

; -----------------------------------------
; Note that the equates MUST be put after
; the procedure names that they equate to.
; -----------------------------------------
lstr equ <szLeft>
rstr equ <szRight>
midstr equ <szMid>
; ******************************

shell PROTO :DWORD

StripRangeI PROTO :DWORD,:DWORD,:BYTE,:BYTE
StripRangeX PROTO :DWORD,:DWORD,:BYTE,:BYTE

MemCopy PROTO :DWORD,:DWORD,:DWORD  ; source - dest - length
memfill PROTO :DWORD,:DWORD,:DWORD

GetAppPath   PROTO :DWORD     ; buffer has app path
NameFromPath PROTO :DWORD,:DWORD
GetPathOnly  PROTO :DWORD,:DWORD

exist PROTO :DWORD
filesize PROTO :DWORD

FrameCtrl   PROTO :DWORD,:DWORD,:DWORD,:DWORD
FrameWindow PROTO :DWORD,:DWORD,:DWORD,:DWORD
FrameGrp    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

Frame3D PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
line    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
circle  PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

DisplayBmp   PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
DisplayIcon  PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
VerticalTile PROTO :DWORD,:DWORD,:DWORD
SetBMcolor   PROTO :DWORD,:DWORD

BmpButton    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

StdOut       PROTO :DWORD
StdIn        PROTO :DWORD,:DWORD
locate       PROTO :DWORD,:DWORD
ClearScreen  PROTO
StripLF      PROTO :DWORD

BrowseForFolder PROTO :DWORD,:DWORD,:DWORD,:DWORD
FontDialog      PROTO :DWORD,:DWORD,:DWORD
ColorDialog     PROTO :DWORD,:DWORD,:DWORD
PageSetupDialog PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
PrintDialog     PROTO :DWORD,:DWORD,:DWORD

Read_File_In    PROTO :DWORD,:DWORD
ofCallBack      PROTO :DWORD,:DWORD,:DWORD,:DWORD
Write_To_Disk   PROTO :DWORD,:DWORD
sfCallBack      PROTO :DWORD,:DWORD,:DWORD,:DWORD
RichEd1         PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
RichEd2         PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

GetPercent      PROTO :DWORD,:DWORD
IntMul          PROTO :DWORD,:DWORD
IntDiv          PROTO :DWORD,:DWORD
IntSqrt         PROTO :DWORD

nrandom         PROTO :DWORD
nseed           PROTO :DWORD

; ---------------------------------
; prototypes for pre-built dialogs
; ---------------------------------
GetTextInput    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
AboutBox        PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
GetFile         PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
LoadList        PROTO :DWORD,:DWORD
IPtoString      PROTO :DWORD,:DWORD
GetIP           PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

    MakeIP MACRO val1,val2,val3,val4
        mov ah, val1
        mov al, val2
        rol eax, 16
        mov ah, val3
        mov al, val4
      EXITM <eax>
    ENDM

; ----------------------------------------
; Ernie Murphy's image loading procedures
; ----------------------------------------
BitmapFromFile      PROTO :DWORD
BitmapFromMemory    PROTO :DWORD,:DWORD
BitmapFromResource  PROTO :DWORD,:DWORD


MichaelW

That looks like the oldest version that I have on my system, dated December 9, 2004. I think you need a new one,  preferably in a new installation from a fresh download.
eschew obfuscation

timertik

#6
ok I just tried the masm version from the main page and it installed perfect unlike previous versions I will tell you if i can assemble my project
EDIT:
with the latest version It will compile and I got it to run but it doesnt work it works in reverse (I think) when it starts it clears out the .ini instead of reading from it and placing it in the edit boxes and when i add something to the edit boxes it saves it to the .ini but after i restart the app it again erases everything in the file
EDIT:
Nevermind that what i was doing was including the write over(Save) code into WM_COMMAND  and when that code ran it erased the editboxes I will work and improve this so it fits my needs better maybe try to save dynamicly or else ill just save on exit  :dance:

everything works now  :bg
thanks for the help

PBrennick

timertik,
There is no reason why you can't have a save option under WM_COMMAND. If the code is running when it should not then you are processing the messages incorrectly. As far as saving on exit goes, you absolutely should do this if it has not been saved yet. You should also be processing the WM_CLOSE message and checking if you need to save there, also.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

timertik

yup I got it all sorted now it saves on exit and saves every time those specific controls are used
it works great and since then i have added 13 more controls that run specifically off the .ini
I also fixed a little message to tell the user if the .ini was missing.
im getting better everyday.  :U