flat assembler
Message board for the users of flat assembler.

flat assembler > High Level Languages > Cannot load function from fasm compiled dll

Author
Thread Post new topic Reply to topic
binary



Joined: 10 Oct 2009
Posts: 26
I have a dll compiled with fasm and a c++ console program. When I load the function from the dll file I receive the error 127(0x7F) The specified procedure could not be found.

Dll code:
Code:
; DLL creation example format PE GUI 4.0 DLL entry DllEntryPoint include 'win32a.inc' section '.code' code readable executable proc DllEntryPoint hinstDLL,fdwReason,lpvReserved mov eax,123456 ret endp proc Hello mov eax,12345 ret endp ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError); proc ShowErrorMessage hWnd,dwError local lpBuffer:DWORD lea eax,[lpBuffer] invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0 invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK invoke LocalFree,[lpBuffer] ret endp ; VOID ShowLastError(HWND hWnd); proc ShowLastError hWnd invoke GetLastError stdcall ShowErrorMessage,[hWnd],eax ret endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetLastError,'GetLastError',\ SetLastError,'SetLastError',\ FormatMessage,'FormatMessageA',\ LocalFree,'LocalFree' import user,\ MessageBox,'MessageBoxA' section '.edata' export data readable export 'ERRORMSG.DLL',\ ShowErrorMessage,'ShowErrorMessage',\ ShowLastError,'ShowLastError' section '.reloc' fixups data discardable


C++ code:
Code:
#include <windows.h> #include <iostream> using namespace std; typedef int (__stdcall *f_funci)(); int main() { HINSTANCE hGetProcIDDLL = LoadLibrary("dll.dll"); if (!hGetProcIDDLL) { cout << "could not load the dynamic library" << endl; return EXIT_FAILURE; } // resolve function address here f_funci funci = (f_funci)GetProcAddress(hGetProcIDDLL, "Hello"); if (!funci) { cout << "could not locate the function " << funci << GetLastError()<< endl; return EXIT_FAILURE; } cout << "funci() returned " << funci() << endl; return 0; }
Post 27 Dec 2017, 10:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15864
Location: 162173 Ryugu
You need to include the name "Hello" in the exports list.
Code:
export 'ERRORMSG.DLL',\ Hello,'Hello',\ ShowErrorMessage,'ShowErrorMessage',\ ShowLastError,'ShowLastError'
Post 27 Dec 2017, 10:41
View user's profile Send private message Visit poster's website Reply with quote
binary



Joined: 10 Oct 2009
Posts: 26
Thank you
Post 27 Dec 2017, 13:34
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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.