flat assembler
Message board for the users of flat assembler.

Index > Windows > dll problem. Windows 10

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
Fasmw 1.73
Code:
format PE64 GUI 5.0 DLL on 'nul'
entry DllEntryPoint

macro PrintInt chTxt,chVal { }
macro PrintInt2 chTxt,chVal {
   cinvoke sprintf,Status22,chTxt,chVal
   invoke  MessageBox, 0,Status22, 0, 0
}
macro Msg chT { invoke  MessageBox, 0,chT, 0, 0 }
include 'C:\fasmw17316\include\win64ax.inc'
include 'C:\fasmw17316\include\macro\if.inc'

section '.data' data readable writeable
          dd 0,0,0,0

section '.code' code readable writeable executable

proc DllEntryPoint hinstDLL, fdwReason, lpvReserved
     mov     rax, TRUE
     ret
endp

; VOID ShowErrorMessage(HWND hWnd,DWORD dwError);
proc ShowErrorMessage hWnd, dwError
     local lpBuffer:QWORD

     mov     [hWnd], rcx
     mov     [dwError], rax

   ;  invoke  FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, 0, [dwError], LANG_SYSTEM_DEFAULT,\
   ;          addr lpBuffer, 0, 0
     invoke  MessageBox, [hWnd], [lpBuffer], 0, MB_ICONERROR or MB_OK
     invoke  LocalFree, [lpBuffer]

     ret
endp

; VOID ShowLastError(HWND hWnd);
proc UsrA
    invoke  MessageBox, 0,'S_data = Null', 0, 0   ;this loadlibrary get error dll !
     ;invoke  MessageBox, 0,mmmm, 0, 0           ;this work fine loadlibrary whitout errors
     mov     eax,0       ;128 = dll_clip
     ret
     mmmm    db 'dll run function !',0
endp

section '.bss' readable writeable
        align 8
        ss2 rq 0        ;how voices
        sss rb 64*2000  ;idet Voice i XA2Buffer na kazdii 64 bytes
        Status22 rd 100

section '.idata' import data readable

  library msvcrt,'MSVCRT.DLL',\
          kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          gdi32,'GDI32.DLL',\
          comctl32,'COMCTL32.DLL',\
          winmm,'WINMM.DLL',\
          ole32,'OLE32.DLL'

  include 'C:\FasmAPI\msvcrt.inc'
  include 'C:\FasmAPI\kernel32.inc'
  include 'C:\FasmAPI\user32.inc'
  include 'C:\FasmAPI\gdi32.inc'
  include 'C:\FasmAPI\comctl32.inc'
  include 'C:\FasmAPI\ole32.inc'
  include 'C:\FasmAPI\winmm.inc'

section '.edata' export data readable

  export 'user1.dll',\
         ShowErrorMessage,'ShowErrorMessage',\
         UsrA,'UsrA'

section '.reloc' fixups data readable discardable  
    


Last edited by Roman on 10 Jul 2022, 20:32; edited 3 times in total
Post 10 Jul 2022, 19:57
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
LoadLibraryA get this error:
---------------------------
test.EXE - Bad Image
---------------------------
C:\FasmAPI\fedit\usrdll\user1.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support. Error status 0xc000007b.
---------------------------
OK
---------------------------
Post 10 Jul 2022, 19:59
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
I tested it with 32-bit DLL, FASM complained:

Code:
Error: value out of range
pushd 'S_data = Null'    


If tested with "mmmm" is OK, as 64-bit DLL.

Also, I think the string needs to be null-terminated.


Last edited by FlierMate1 on 11 Jul 2022, 00:34; edited 2 times in total
Post 10 Jul 2022, 20:44
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1
Roman wrote:
LoadLibraryA get this error:
---------------------------
test.EXE - Bad Image
---------------------------
C:\FasmAPI\fedit\usrdll\user1.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support. Error status 0xc000007b.
---------------------------
OK
---------------------------


I got this in Visual Studio (for 64-bit DLL).
Update: It was because my fault for not setting environment to x64.


Description:
Filesize: 54.28 KB
Viewed: 414 Time(s)

Screenshot 2022-07-11 042307.png




Last edited by FlierMate1 on 11 Jul 2022, 00:29; edited 1 time in total
Post 10 Jul 2022, 20:46
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 688
Location: Russian Federation, Sochi
ProMiNick
Code:
invoke  MessageBox, 0,'S_data = Null', 0, 0   ;this loadlibrary get error dll !    
- that is yakk coding style, it was applied to 32bit api call because of stack using and some trickering and honesty looks ugly
when thou moved to 64 bit pass to MessageBox ptr, not string itself.

But if thou realy realy want that feature for x64. (Я постебусь и реализую эту функцию, только время компиляции увеличится в 1000 раз, и процессорного ресурса по памяти отожрется столько что программу/библиотеку более чем с 10 64битными инвоками ты не скомпилируешь, кстати реализовывать всякий синтаксический мусор и правда затратно для препроцессора, просто в случае соглашения о вызовах для 32 битов так удачно совпало, что решение простое)
so, do thou need it for x64?(так тебе нужен этот синтаксический мусор?)
Post 11 Jul 2022, 00:04
View user's profile Send private message Send e-mail Reply with quote
I



Joined: 19 May 2022
Posts: 31
I
Because of empty relocation table (zero length). Not sure if "rq 0" is useful either, typo?
Post 11 Jul 2022, 00:55
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
Some times I need for debug Dll print messages.
Messagebox, 0,“debug info“, 0,0
And I do this using macro Msg.
When I finish tested Dll, then I do macro Msg empty.
This remove all debug messages.
For this reason I using this ugly style.
Its more handful and no needed write text data.

I rewrite my macro Msg. And deleted proc ShowErrorMessage(guilty of a error too).
And fix this problem. Now dll work fine, no errors
Code:
macro Msg chT { local .txtl,.ll
      jmp .ll
      .txtl db chT,0
.ll: invoke  MessageBox, 0,.txtl, 0, 0 }
    
Post 11 Jul 2022, 04:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.