Solved 3rdparty DLL with TD

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

3rdparty DLL with TD

Post by ivano_osti » 18 Dec 2006, 20:14

 Posted by:  Ivano Edilberth Osti 

Hi. I'm not new with TD. I've already worked with 3rdparty dll's but I have
no idea on how to use MoviLink.dll

I would thank you a lot if you give me a TD sample of ml_sample.txt or just
tips on how to use the DLL with TD. Any tip is welcome as I'm starting...

Thanks in advance.

My best regards.
You do not have the required permissions to view the files attached to this post.

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 19 Dec 2006, 20:45

Hi. I've put this subject yesterday in forum.td.development but no answers
until now. Maybe it's the right newsgroup.

Excuse-me my insistence. It's because I'm fighting with the DLL.

My manager wants to use other language because I'm not having success with
TD.

Any tip is welcome.

Thank you.

PS: I'm using CTD 1.5.1-PTF6

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3384
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: 3rdparty DLL with TD

Post by Dave Rabelink » 19 Dec 2006, 23:44

It is late here, but maybe I can put you to the right direction.

The MoviLink dll has these exported functions :

Code: Select all

       8   CvtAdr2Long
       7   GetDeviceSignature
       6   GetDeviceType
       4   GetMOVILINKVersion
       5   GetTypeString
       1   MoviLink
       9   Netware
       2   ReadSharedMem
       3   WriteSharedMem
The ordinal number is in placed in front of the list above.

The function declarations are these :

Code: Select all

BOOL GetMOVILINKVersion(LPSTR pszText, INT maxlen);
BYTE MoviLink(FPSERVICE);
BOOL WriteSharedMem(LPSTR lpMem, WORD wlen, SHORT sOffset);
BOOL ReadSharedMem(LPSTR lpMem, WORD wlen, SHORT sOffset);
BOOL GetDeviceType(WORD wAdr, LPSTR lpName, WORD len);
BOOL GetTypeString(LONG lWert, LPSTR lpName, WORD len);
LONG CvtAdr2Long(PBYTE pbAdr);
BOOL GetDeviceSignature(WORD wAdr, LPSTR lpName, WORD len);
So you should add the dll declarations in the TD external functions
section.

The FPSERVICE parameter of the MoviLink function is a structure,
defined like this :

Code: Select all

    typedef struct tagSERVICE
      {
      unsigned char  bService,        //service to execute
                     fShortCnf;       //short confirmation enable
      unsigned short wTargetAddress;  //target address or PC-interface
      unsigned short wIndex,          //Parameter-Index
                     wDataLength;     //Anzahl PD bei READ..., WRITE..bzw. Nutzdaten bei SCOPE
      unsigned char  bTeleType;       //0:zykl. sonst: azyklische Telegramme

      union
        {
        long          lDate;         //Standard-READ, WRITE-Dienst
        unsigned char abData[10];    //abData[0]:Kanal-Nr. bei GET_SCOPE
        }Data;                       //abData[1]:Block-Nr. bei GET_SCOPE

      unsigned short awPA[10],       //zu sendende Prozessdaten
                     awPE[10];       //empfangene Prozessdaten

      unsigned char far* fpbDataPointer;
      unsigned char      abReserve[10];
      ERRORMSG           Error;
      }SERVICE, far* FPSERVICE;
  #endif
This structure is the TD structpointer parameter with all the
attributes defined like in the C sample above. Create the
structpointer members exactly as described in the C sample struct
layout.

You could also create a structure using the TD CStruct library, which
has a function to create far memory using CStructAllocFarMem function.
Using the functions CStructPutWord, CStructPutLong etc etc you can
write data to the memory according to the size of the seperate
structure members. This farpointer can be used as a parameter in the
MoviLink function.

But i would first try to create the MoviLink function declaration
using the structpointer way.

I just quickly looked at the dll and the C sample, but maybe this
brief explanation could bring you further.

Dave

Stefan Beltrame

Re: 3rdparty DLL with TD

Post by Stefan Beltrame » 19 Dec 2006, 23:48

 Posted by:  Stefan Beltrame 

... and here is the code

Late at night - waiting for my wife comming home - I had nothing better to
do then write this lines of code ;-)

Regards
Stefan

P.S. It's written in TD 3.1. So maybe you have to change the Outline Version
in the APT file.

You do not have the required permissions to view the files attached to this post.

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 20 Dec 2006, 16:54

Hi Dave and Stefan.

I'm feeling more alliviated now.

I'll try your tips/samples and I let you know about the results as soon as
possible.

Thank you a lot for your answers. I've now a way to go.

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 21 Dec 2006, 21:01

 Posted by:  Ivano Edilberth Osti 

Hi Stefan.

Your sample worked very well and helped me a lot. I could read values from
the device. I'll add some code in your sample to write values to the device.
I hope to not have problems.

Count on me.

Thank you.

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 21 Dec 2006, 21:16

 Posted by:  Ivano Edilberth Osti 

Hi Dave.

The Stefan's sample worked fine but I'm also trying your tip of
structpointer way.

With your tip, I had success to read values from the device but I don't have
the errors (ERROMSG Error structure). I have this in the Stefan's sample.

I suppose that I haven't declared correctly the parameters of MoviLink
function. I've declared like this:

Code: Select all

structPointer
 Number: WORD
 Number: WORD
 Number: WORD
 Number: WORD
 Number: WORD
 Number: WORD
 struct
  Receive Number: LONG
  String: char[10]
 Number: WORD
 Number: WORD
 Number: BYTE
 Number: BYTE
 struct
  Receive Number: BYTE
  Receive Number: BYTE
  Receive Number: BYTE
  Receive Number: BYTE
Do you have an idea about my mistake? How would you declare the parameters?

You helped me a lot.

Count on me.

Thank you.

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 21 Dec 2006, 21:19

 Posted by:  Ivano Edilberth Osti 

I forgot to say that I get the "read value" from the device in the 7th
parameter (Receive Number: LONG).

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: 3rdparty DLL with TD

Post by Jeff Luther » 21 Dec 2006, 21:44

I think at least this part in your declaration:
> struct
> Receive Number: LONG
> String: char[10]

is wrong, Ivano. The declaration says it's a "union" - that is, *either* the
parameter is passed back as a LONG pointing to a date *or* a pointer to an
array of 10 bytes, depending. Here's what the H file says about this:

Code: Select all

       union
         {
         LONG lDate;         //Standard-READ, WRITE-Dienst
         BYTE abData[10];    //abData[0]:Kanal-Nr. bei GET_SCOPE
         } Data;                       //abData[1]:Block-Nr. bei GET_SCOPE
So, I read that as: If either a standard-read or write-service is done, the
value back is a date in a LONG (4-byte) value. I believe the declaration
should be:

Code: Select all

	Receive Number: LONG
only; your code then decides whether to treat that as a date or a long
pointer to an array of 10 bytes. (I think that's correct.)

Stefan seems to have the date decoding right with his:

Code: Select all

If nRet = 0		! JL: that is, nRet = MLEC_ERROR_FREE
	Set nDate = CStructGetLong(strService, 12)
	Call SalMessageBox('Service.Data.lDate: ' || SalNumberToStrX(nDate, 0), 'Message', MB_Ok)
("12" being 6 * #-of-WORDs from the start of the structure) = 6 * 2-bytes-each = 12.

Best Regards,
Jeff Luther/PC Design
info: www.pulpcards.com/gupta/

Stefan Beltrame

Re: 3rdparty DLL with TD

Post by Stefan Beltrame » 22 Dec 2006, 00:18

 Posted by:  Stefan Beltrame 

Sorry to jump in

UNION means that all variables are starting at the same memory address. The
largest variable, in this case abData[10], defines the amount of memory.

So you have to use

Code: Select all

structPointer
    Number: WORD
    Number: WORD
    Number: WORD
    Number: WORD
    Number: WORD
    Number: WORD
    struct
        Receive Number: LONG
        String: char[6]        ! 6 bytes + 4 bytes fom LONG = 10 bytes
    Number: WORD
    Number: WORD
    Number: BYTE
    Number: BYTE
    struct
        Receive Number: BYTE
        Receive Number: BYTE
        Receive Number: BYTE
        Receive Number: BYTE
Another solution could be

Code: Select all

...
struct
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
    Receive Number: BYTE
...
To get the long value you have to calculate it out of the first 4 Bytes.

Regards
Stefan

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 22 Dec 2006, 13:38

 Posted by:  Ivano Edilberth Osti 

Hi Jeff and Stefan.

I've tried your tips but with no success. I don't know if I'm making
mistakes.

I'll give up the "structpointer way" for this moment as I need to start with
the project as soon as possible. I'll work with the Stefan sample.

I intend to try the "structpointer way" again with more time. I'm rushing
into with the project now.

If you have some more "structpointer way" tip or sample, I can try again as
I'm starting the project.

Dave/Stefan/Jeff: Thank you all. You helped me a lot...

My best regards.

Stefan Beltrame

Re: 3rdparty DLL with TD

Post by Stefan Beltrame » 22 Dec 2006, 15:03

 Posted by:  Stefan Beltrame 

Here we are...

Personally I would use the CStruct - Solution.

Regards
Stefan

You do not have the required permissions to view the files attached to this post.

ivano_osti
Brazil
Posts: 415
Joined: 17 Nov 2017, 20:02
Location: Itapira-SP, Brazil

Re: 3rdparty DLL with TD

Post by ivano_osti » 27 Dec 2006, 19:37

 Posted by:  Ivano Edilberth Osti 

Hi Stefan.

The sample worked pretty good and it is very important to me to understand
better how to deal with "structpointers". I'll follow your recommendation to
use "CStruct" solution that was your previous sample. It's really better.

I hope one day to repay your attention.

Thank you a lot.

Count on me.

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests