News:

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

Error In BUFFER_SIZE And In StdIn

Started by nathanpc, October 06, 2009, 11:41:41 PM

Previous topic - Next topic

nathanpc

Hello,
I was trying to do a DLL(just to pratice more) that manipulates the Clipboard, but i'm getting some errors in BUFFER_SIZE and in the invoke of StdIn, see my code:
.386
option casemap :none   ; case sensitive
include \masm32\include\masm32rt.inc
.data
    szType   db 'Type the text: ', 0
    format1 db 10, 'Clipboard = %u', 0

.data?
    buffer      db BUFFER_SIZE dup(?)
    buffer2     db BUFFER_SIZE dup(?)

.code
LibMain proc instance:dword,reason:dword,unused:dword
    mov eax,1
    call ClipBoard
    inkey
    exit
    ret
LibMain     endp

ClipBoard proc
    local ptxt:DWORD
    invoke StdOut, ADDR szType
    invoke StdIn, ADDR buffer, BUFFER_SIZE
   
    mov BYTE PTR [buffer+eax-2], 0
    invoke  CreateFile, ADDR buffer, GENERIC_READ, 0, 0, \
                  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
    cmp eax, INVALID_HANDLE_VALUE
    je finish
    mov ptxt, eax
    fn SetClipboardText, eax
    invoke GetClipboardText
    mov ptxt, eax
    invoke  wsprintf, ADDR buffer2, ADDR format1, eax
    invoke  StdOut, ADDR buffer2
    invoke GlobalFree, ptxt
   
   
    finish:
         invoke  ExitProcess, 0
   
ClipBoard endp

End LibMain

And the compiler log:
D:\Masm32\Bin\ML /c /coff /Cp /nologo /I"D:\Masm32\Include" "D:\Clipboard\clipdll.asm"

Assembling: D:\Clipboard\clipdll.asm
D:\Clipboard\clipdll.asm(9) : error A2006: undefined symbol : BUFFER_SIZE
D:\Clipboard\clipdll.asm(10) : error A2006: undefined symbol : BUFFER_SIZE
D:\Clipboard\clipdll.asm(24) : error A2006: undefined symbol : BUFFER_SIZE
D:\Clipboard\clipdll.asm(24) : error A2114: INVOKE argument type mismatch : argument : 2

D:\Masm32\Bin\Link @"D:\Clipboard\link.war"

Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 "/LIBPATH:D:\Masm32\Lib" /DLL "D:\Clipboard\clipdll.obj" "/OUT:D:\Clipboard\clipdll.dll"
LINK : fatal error LNK1181: cannot open input file "D:\Clipboard\clipdll.obj"

Make finished. 5 error(s) occured.


Best Regards,
Nathan Paulino Campos

MichaelW

I would think that it would be obvious what the immediate problem is - BUFFER_SIZE is not defined so ML does not know what value to assign to it. You need to define it somewhere above the first reference to it, for example:

BUFFER_SIZE equ 1024

Also, since the call to the ClipBoard procedure never returns LibMain cannot return TRUE, so the DLL will not load normally. If I were doing this I would use a test app to load the DLL and call the ClipBoard procedure, and code the procedure so it would return a success or failure indicator to the caller.
eschew obfuscation

nathanpc


nathanpc

ut now i corrected my code, but when i start the program that calls the DLL it show me a Windows error, see the DLL code:
.386
option casemap :none   ; case sensitive
include \masm32\include\masm32rt.inc
BUFFER_SIZE equ 1024
.data
    szType   db 'Type the text: ', 0
    format1 db 10, 'Clipboard = %u', 0

.data?
    buffer      db BUFFER_SIZE dup(?)

.code
LibMain proc instance:dword,reason:dword,unused:dword
    mov eax, 1
    ret
LibMain     endp

ClipBoard proc
    local ptxt:DWORD
    invoke StdOut, ADDR szType
    invoke StdIn, ADDR buffer, BUFFER_SIZE
   
    mov BYTE PTR [buffer+eax-2], 0
    mov ptxt, eax
    fn SetClipboardText, eax
    invoke GlobalFree, eax
   
    inkey
    exit
ClipBoard endp

End LibMain

And the program that calls the DLL:
.386
.model stdcall,flat
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.data
    hLib dword ?
    hProc dword ?

.data
    lib byte "clipdll.dll", 0
    function byte "ClipBoard", 0

.code
start:
    push offset lib
    call LoadLibrary
    mov hLib, eax

    push offset function
    push hLib
    call GetProcAddress
    mov hProc, eax

    call hProc ; will call your function in your DLL

    push hLib
    call FreeLibrary ; free the resource

    ret
end start

Why?

MichaelW

Your code is not complete, so I created a simple example that uses Load-Time Dynamic Linking.

BTW, makeit.bat creates the DLL and the import library, and dlltest.asm is a test program that must be built as a console app.
eschew obfuscation

nathanpc

Now i tryed to compile the DLL using a definition file, but now the Windows error appears when i type the text and hit enter.
What is wrong now?

Best Regards.