如何处理:应用程序没有从我的 dll 中看到 func

How to deal: app does not see func from my dll

创建了一个 dll 和一个应用程序来测试 dll 的进程。

程序计算一个字符的重复次数。

代码:

dll:

.586
.model flat, stdcall
option casemap: none 

include C:\masm32\include\windows.inc 
include C:\masm32\include\user32.inc 
include C:\masm32\include\msvcrt.inc

includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\user32.lib 

.data
msg_string db 'Enter string: ', 0
msg_symbol db 'Enter symbol: ', 0
result db 'Count = %d', 0
str_modifier db '%s ', 0
sym_modifier db '%c', 0

.data
string db ?
symbol db ?

.code
DllEntry PROC hInstDLL:DWORD, reason:DWORD, reserved:DWORD  
    mov  eax, 1  
    ret 
DllEntry ENDP 

symbol_count PROC EXPORT 
    
    invoke crt_printf, OFFSET msg_string
    invoke crt_scanf, OFFSET str_modifier, OFFSET string
    invoke crt_printf, OFFSET msg_symbol
    invoke crt_scanf, OFFSET sym_modifier, OFFSET symbol
    
    xor esi, esi
    xor ecx, ecx

    mov ebx, OFFSET string
    mov al, symbol
loop1:
    cmp byte ptr [ebx + ecx], 0
    je endloop
    cmp al, byte ptr [ebx + ecx]
    jne next
    inc esi
next:
    inc ecx
    jmp loop1 
endloop:
    
    invoke crt_printf, OFFSET result, esi
    
    ret 

symbol_count ENDP 

End DllEntry

如果我有更好的编码方法,也请告诉我。在互联网上很难找到所需的信息。谢谢。

测试应用:

.586
.model flat, stdcall
option casemap: none 

include C:\masm32\include\windows.inc 
include C:\masm32\include\user32.inc 
include C:\masm32\include\msvcrt.inc

includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\user32.lib 

LoadLibraryA proto LibName:DWORD
GetProcAddress proto hLib:DWORD, FunctionName:DWORD
FreeLibrary proto hLib:DWORD
ExitProcess proto uExitCode:DWORD

.data
LibName db 'Labor07.dll', 0
FunctionName db '_symbol_count@0', 0
DllNotFound db 'cannot find the dll', 0
AppName db 'Load explicit dll', 0
NotFound db 'Func is not found', 0
msg db 'Hello', 0
hLib dd ?
symbol_count_addr dd ?

.code
start:
    
    invoke LoadLibraryA, addr LibName
    .if eax == NULL
        invoke MessageBoxA, NULL, addr DllNotFound, addr AppName, MB_OK
    .else
        mov hLib, eax
        invoke GetProcAddress, hLib, addr FunctionName 
        .if eax == NULL
            invoke MessageBoxA, NULL, addr NotFound, addr AppName, MB_OK
        .else
            push offset msg 
            mov symbol_count_addr, eax 
            call [symbol_count_addr] 
        .endif
        invoke FreeLibrary, hLib 
    .endif 
    invoke ExitProcess, NULL 
end start

结果是消息框:

更新#1

结果:

%path%>Project4
Enter string: asfasf
Enter symbol: Count = 1
%path%>

更新 #2

%path%>project4
Enter string: asfasfasf
a
Enter symbol: Count = 4
%path%>

labor07.dll 使用 STDCALL (.model flat, stdcall)。因此,函数的名称将被修饰:_symbol_count@0.

改变

FunctionName db 'symbol_count', 0

FunctionName db '_symbol_count@0', 0

此外,必须导出函数 symbol_count

改变

symbol_count PROC

symbol_count PROC EXPORT