Problem with DLL written in MASM32 to call from another language

Started by asm4all, February 08, 2012, 12:42:14 AM

Previous topic - Next topic

asm4all

I have written a simple DLL in MASM32 with a module to call from another language (specifically APL2000's APL-PLUS Win).  I am an expert APL programmer and an experienced assembler programmer, but the last DLL I wrote for mixed language use was 10 years ago. 

I wrote the DLL using Hutch's QuickEditor 4.0g, and it's very simple.  The source code is reproduced below.  It assembles successfully in the IDE.  However, when I call it from within APL, I get a MODULE NOT FOUND error. 

When calling a DLL from most languages, this would implicate the PATH environment variable, but this DLL is located in the same path as the APL workspace that calls it (and APL does not have a separate PATH environment variable). 

I wonder if this source code reveals the reason why the module is not found. 

Any ideas would be most appreciated. 

Thanks.

Here's the source (the module is AddUp): 

LibMain proc instance:DWORD,reason:DWORD,unused:DWORD

    .if reason == DLL_PROCESS_ATTACH
      mrm hInstance, instance       ; copy local to global
      mov eax, TRUE                 ; return TRUE so DLL will start

    .elseif reason == DLL_PROCESS_DETACH

    .elseif reason == DLL_THREAD_ATTACH

    .elseif reason == DLL_THREAD_DETACH

    .endif

    ret

LibMain endp

AddUp Proc STDCALL InVal:DWord
   Mov Eax,InVal
   Add Eax,4
   Ret
AddUp EndP

end LibMain


hutch--

I don't know my way around APL but if it produces an EXE fle, I would be inclined to have a look at its imports and see what the DLL import for your DLL looks like. You do have to make sure you have exported the function you have written, this is usually done in a DEF file. If you are calling it dynamically ( LoadLibrary() GetProcddress() )  you would have to test the return values for both the library and the procedure to see i8f you get valid results.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

vanjast

Try putting the DLL in the 'xx:\windows\system32' folder, otherwise as hutch says

Tedd

Normally, the DLL should be on the same path as the EXE that tries to load it, which probably isn't the same path as the workspace you're currently running. Since it's the interpreter that actually runs the workspace, the DLL would need to be in a place it will look - either on the same path as the interpreter, or there should be some option to tell the interpreter where to check for additional DLLs.
Alternatively, placing your DLL in the "system32" folder will make it available to anyone.
No snowflake in an avalanche feels responsible.

asm4all

Thanks for the replies.  This was solved by placing the .dll in the root interpreter directory, as Hutch suggested.  I had placed it in the directory that contains my application workspace, and it could not be found there.