xxx.asm
%define p1 ebp+8
%define p2 ebp+12
%define p3 ebp+16
section .text
global dllmain
export astrlen
dllmain:
mov eax,1
ret 12
astrlen:
push ebp
mov ebp,esp
mov ecx,[p1] ; char ptr
xor eax,eax
.for:
cmp byte [ecx],0
je .return
inc ecx
inc eax
jmp .for
.return:
mov esp,ebp
pop ebp
ret 4
link.fil:
/entry dllmain
/dll
xxx.obj
c++
#include <iostream>
#include <Windows.h>
typedef int (CALLBACK* astrlen_t)(const char*);
astrlen_t astrlen;
int main()
{
HMODULE myDLL = LoadLibraryA("xxx.dll");
astrlen = (astrlen_t)GetProcAddress(myDLL, "astrlen");
printf("%d
", astrlen("hello world")); // 11
printf("%d
", astrlen("nasm")); // 4
return 0;
}