Magic User Group

Magic Wiki-Wakka : StandardDLLs

HomePage :: CATEGORIES | Index :: Changes :: Comments :: Search :: Login/Register

Standard DLLs


A DLL is a Windows dynamic link library and its Microsoft's implementation of the shared library concept of Unix.
In contrast to "Magic DLLs", we refer to regular Windows DLLs as "Standard DLLs".

The term "Standard DLL" you hardly find in any available Magic/eDeveloper documentation. eDeveloper documentation distincts between calls to external STDCALL functions and calls to external CDECL (FASTCALL) functions. See the page on calling conventions and available eDeveloper documentation for more explanation on these terms. This is a bit confusing but basically its because a "external STDCALL function" could also be a function residing in a Unix shared library. Magic/eDeveloper is platform independent and CALL UDP/UDF() you can use on any of the avilable platforms. DLLs do only exist on MS Windows.

A "Standard DLL" therefore is a not just a DLL which Magic requires to have STDCALL calling conventions. It is also required to have all its available functions exported (which is always the case for regular Windows DLLs) and only for "Magic DLLs", which have a different concept for finding the address of exported functions, not.

A "Standard DLL" therefore is something we define to be "a Windows DLL which has its functions exported AND uses calling convention STDCALL (_stdcall / WINAPI) for all these exported functions". To better understand what "exported function" means, use some of the utilities listed at the end of this document to look inside a DLL. They'll list you the exported functions of a particular DLL, give some in-sight and help trouble-shooting DLL problems.

A Windows DLL in principal contains code (exported functions) and data which is reused when several applications access the same DLL. Reusage of data however is no longer possible in 32-Bit versions of Windows. In 16-Bit versions of Windows it was and it effectively allowed sharing of data between applications.

.NET has refined Windows' concept of DLLs and .NET people you'll often hear talk about "assemblies". Assemblies basically are the "next generation DLLs". More on this and how to use them in available documentation regarding eDeveloper and .NET.



Support for "Standard DLLs" was added to Magcic/eDeveloper in Version 8. Before ONLY "Magic DLLs" were supported. 8.3 elaborated the support of DLLs once more and allowed different calling conventions to be explicitely specified.

See the page on "Magic DLLs" for more information regarding the evolution of DLL support in Magic/eDeveloper.



calling a function within a "Standard DLL"


You invoke functions in "Standard" DLLs with functions CallDLL(), CallDLLS(), CallDLLF() and CALL (v10: Invoke) UDP.

See the page on calling conventions regarding information about which function you need to use exactly (and how). See pages about Windows API and [CallingDLLsTest "calling convention tests"] for some samples and further explanantion.

Almost always however it will be function CallDLLS() which has to be used to call a function residing in a "Standard DLL".

You can also use Magic's CALL UDP operation to call a function residing in a "Standard DLL". This is particular useful since only the CALL UDP operation allows external functions to alter any of the parameters AND return a value. The CallDLL() function familiy and UDF() functions can ONLY return a value.

If you use CallDLL for invocation and the function changes any of the parameters given to it, the changes are not reflected inside Magic. Magic passes a copy of the actual parameter. CallDLL therefore only supports "call by value". CALL UDP supports "call by reference" as well.

If you use CALL (v10: Invoke) UDP to invoke a function in a "Standard DLL" you need to prefix the module name with an "@" sign to tell Magic that its a Standard-, non-Magic, DLL. You then also need to specify a parameter type string as first argument and a (possible) return value as last argument. See available eDeveloper Documentation and samples on this site for additional information. Be sure to have the "calling convention" selection set to "Standard".

If you try to invoke CALL UDP for a "Standard DLL" test.dll without the prefixing "@", invocation will fail with following error: "Failed to load driver: TEST.DLL"

This is because Magic/eDeveloper now expects the DLL to be a "Magic DLL"

Only CALL UDP supports this special "@" notation for module names. UDF (family) and CallDLL (family) of functions do not. If you e.g. try to invoke CallDLL on a function test_func residing in "Standard DLL" test.dll with following expression:
CallDLLS('@test.test_func', 'A4', A)

Invocation will fail with following error:
"Failed to load driver: @TEST.DLL"

Correct invocations for test_func in (Standard DLL) test.dll from within Magic/eDeveloper >= 8.3 are:

Select Virtual A (Alphanumeric 128)
Select Virtual B (Numeric 10)
Update B = CallDLLS ('test.test_func', 'A4', A)

Select Virtual A (Alphanumeric 128)
Select Virtual B (Numeric 10)
CALL UDP '@test.test_func', cnv: "Standard", Parameters: ('A4', A, B)//




DLL inspection and trouble-shooting tools


Probably the most famous tool in this family of utilities is Dependency Walker which you can download from http://www.dependencywalker.com.

If you download this you can peek inside any file (usually .dll or .exe) and see lots of things of which the list and names of exported functions is only one and which shows up in the right pane of this utility.

If you select "handled file extensions" in options menu and add EXE and DLL there, you can right click .exe and .dll files in Explorer and Dependency Walker will show up in the contect menu and start if you select it.

This tool has plenty of other, advanced, features of which paricular the "profiling mode" is interesting for trouble-shooting problems.

Note: Since there's no way to read the required calling convention from a DLL besides looking into the diassembly and guessing by analysis of the prolog/epilog code, Dependency Walker can also not help with this issue.



See also:
- "Magic DLLs"
- calling Windows API functions
- calling DLLs test page
- eDeveloper online help on topics CallDLL, CallDLLS, CallDLLF, UDF, UDFS, UDFF and CALL (UDP) operation

Useful resources:
- Dependency Walker

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki trunk
Page was generated in 0.1169 seconds