DLL trouble

Giganews Newsgroups
Subject: DLL trouble
Posted by:  Markus (markus.hu…@freenet.de)
Date: 30 Mar 2006

Hello,

I've got a dll with these functions/procedures exported:

  procedure init; STDCALL;
  function  init_kommunikation(art:DWORD; portname:PCHAR;
            socketport:WORD; callback:tKommunikationcallback)
            :tcommunicationhandle; STDCALL;
  function  get_dll_info:tebmcomlibrary_info; StdCall;
  function  send_data(handle:tcommunicationhandle;
            p:tPSendBuffer; size:DWord):tLisaNtError; STDCALL;
  function  check_handle(handle:tcommunicationhandle):BOOL;
            STDCALL;

All are STDCALL and exported like this:

EXPORTS
  get_dll_info,  //index 1,
  send_data,    //index 2,
  check_handle,  //index 3;
  init,          //index 4,
  init_kommunikation; // index 5,

The declarations of some parameters are this:
type
  tKommunikationcallback =
    PROCEDURE(s:tSendbuffer; size:DWORD; quelle:PCHAR) of object;
  tcommunicationhandle = WORD;

  tebmcomlibrary_info = packed RECORD
                          dll_version  :WORD;
                          debug_build  :BOOLEAN;
                          konverter    :WORD;
                          maxhandles  :WORD;
                          maxusbhandles:WORD;
                          max232handles:WORD;
                          maxudphandles:WORD;
                          buffersize  :DWORD;
                          echotimeout  :WORD;
                          echotestchar :AnsiChar;
                          usbpolling  :WORD;
                          connection  :BOOLEAN;
                          reserviert:ARRAY[1..233] OF BYTE;
                        END;

  tSendbuffer  = ARRAY[1..256] OF BYTE;
  tPSendBuffer = ^tSendbuffer;
  tLisaNtError = Integer;

The test app and the dll are both compiled with this setting:
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M+,N+,O-,P+,Q+,R+,S-,T-,
U-,V+,W-,X+,Y+,Z1}

In a test application the dll is loaded via loadlibrary and the procedures are imported via GetProcAddress. Some address is returned but calling these mostly hangs. If one follows the call in the CPU-window, one sees that the first thing done after the call of the procedure (also within it) is a jump to a memory adress which seems to be "nirvana".

If you shorten the name of init_kommunikation to init_kommunik then this one works, but a test of send_data fails with the same results as before. So there must be some fundamental bug still in it.

How can I find it?
What tools can I use?
What should I do?

Oh, I'm using Delphi 2006 Arch. if that matters.

Greetings

Markus

Replies