News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using MASM DLLs in other languages

Started by Danesh, April 02, 2005, 07:14:09 PM

Previous topic - Next topic

Danesh

Hi all,

Can I use a DLL which has been created in MASM in other languages such as Delphi or VB ? I know it is possible to use MASM DLLs in VC. My question might be silly, because DLL is a standard format which is supposed to be useable in all programming languages, but I just want to be sure.

Thnaks,

Danesh


Vortex

Hi Danesh,

No, your question is a logical one, you can use Masm DLLs with VB or Delphi.

Danesh

Hi Vortex,

Thanks for your help. Now I am sure about it.  :U


hutch--

Danesh,

The trick is to understand the language you want to call the DLL from. A DLL is a standard interface but some languages have problems calling forms set up in other languages so you need to keep this in mind.

Numbers are easy enough in most instances as long as the calling language support both signed and unsigned numbers but string data can be problematic. With a DLL written in MASM, you can cater for any of the other string formats but for example if you wrote a string handler that required a format used in basic, the calling language may not easily do this and likewise if you use zero terminated strings, some other languages don't do this easily either.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Hi Danesh,

As Hutch said, the most critical part of the job is to do the correct function declaration. You should check Visual Studio's API Viewer to understand how VB handles external functions.

Example:
MessageBox is a well-known function from user32.dll

Visual Basic:
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long,
ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long

Masm:
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox equ <MessageBoxA>

Visual C++:
WINUSERAPI
int
WINAPI
MessageBoxA(
    HWND hWnd ,
    LPCSTR lpText,
    LPCSTR lpCaption,
    UINT uType);

Danesh

I see. Thanks, so I have to test it more while I am creating a DLL with MASM which works only with strings. But as you said it would be risky.

Thank you so much,

Danesh


hutch--

Danesh,

The main distinction with string data in Windows is between zero terminated strings that are passed as addresses and OLE strings that are passed as string handles. When you pass a zero terminated string to a DLL, you usually must be able to place the results back into the same string unless you pass a seperate buffer to te DLL as well. There are a few options here, you can copy the data into allocated memory and pass the handles as well but if you are working with a specific language, you must know how it handles strings.

The advantage with strings passed as a handle is you can reallocate the buffer the string is contained in to make it larger if you need to.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php