1
2
3
4
5
6
7
8
9
10
11
12
13
use strict;
use warnings;
use v5.10;
use Win32::API;
Win32::API->Import('AdsDll.dll', 'LONG AdsGetDllVersion()') or die "$!";
my $pt = AdsGetDllVersion() or die "AdsGetDllVersion failed: $^E";
say $pt;
####Ergebnis seitens DLL Codiert
123456
1
2
3
4
5
6
7
8
typedef struct
{
unsigned char version;
unsigned char revision;
unsigned short build;
} AdsVersion;
typedef AdsVersion* PAdsVersion;
1
2
3
4
5
6
7
8
9
10
11
12
13
void main()
{
long nTemp;
AdsVersion* pDLLVersion;
nTemp = AdsGetDllVersion();
pDLLVersion = (AdsVersion *)&nTemp;
cout << "Version: " << (int)pDLLVersion->version << '\n';
cout << "Revision: " << (int)pDLLVersion->revision << '\n';
cout << "Build: " << pDLLVersion->build << '\n';
cout.flush();
getch();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use warnings;
use v5.10;
use Win32::API;
use Win32::API::Struct;
use Data::Dumper;
BEGIN{
}
Win32::API::Struct->typedef(
'POINT', qw (
UCHAR version;
UCHAR revision;
USHORT build;
)
) or die "Typdef error $!\n";
my $pt = Win32::API::Struct->new('POINT');
say $pt->sizeof();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use strict;
use warnings;
use v5.10;
use Win32::API;
use Win32::API::Struct;
use Data::Dumper;
BEGIN{}
Win32::API::Struct->typedef(
'POINT', qw (
PCHAR version;
PCHAR revision;
PSHORT build;
)
) or die "Typdef error $!\n";
my $pt = Win32::API::Struct->new('POINT');
say $pt->sizeof();
Win32::API->Import('AdsDll.dll', 'LONG AdsGetDllVersion()') or die "$!";
$pt = AdsGetDllVersion('POINT') or die "AdsGetDllVersion failed: $^E";
say $pt->version;
$pt = AdsGetDllVersion() or die "AdsGetDllVersion failed: $^E";
1
2
3
4
5
my @Data = unpack "CCs", pack "l", $long;
$pt -> {version} = $Data[0]
$pt -> {reversion} = $Data[1]
$pt -> {build} = $Data[2]
($pt->{version},$pt->{reversion},$pt->{build}) = unpack "CCS", pack "l", $long;
@{ $pt }{qw( version revision build ) } = unpack ...;
1
2
3
4
5
6
7
8
9
Win32::API::Struct->typedef(
'POINT', qw (
UCHAR version;
UCHAR revision;
USHORT build;
)
) or die "Typdef error $!\n"
my $pt = Win32::API::Struct->new('POINT');
$pt = unpack...
1
2
3
4
5
6
7
8
9
10
use strict;
use warnings;
use v5.10;
use Win32::API;
use Win32::API::Struct;
use Data::Dumper;
Win32::API->Import("$Dll", 'LONG AdsGetDllVersion()') or die "$!";
$LONG = AdsGetDllVersion() or die "AdsGetDllVersion failed: $^E";
@{$Data}{qw (version reversion build)} = unpack "CCS", pack "l", $LONG;
print Dumper ($Data);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
long nErr, nPort;
AmsAddr Addr;
PAmsAddr pAddr = &Addr;
// Kommunikationsport auf dem ADS Router öffnen
nPort = AdsPortOpen();
nErr = AdsGetLocalAddress(pAddr);
typedef struct {
AmsNetId netId;
USHORT port;
} AmsAddr, *PAmsAddr;
typedef struct {
UCHAR b[6];
} AmsNetId, *PAmsNetId;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use strict;
use warnings;
use v5.10;
use Win32::API;
my $ObjDll = {
_OpenPort => GetRefToDllFunction("$Path2Dll", 'AdsPortOpen', '', 'N'),
_LocalAddr => GetRefToDllFunction("$Path2Dll", 'AdsGetLocalAddress', '???', 'N')
};
sub GetRefToDllFunction(....);
# Port öffnen, Rückgabewert des offenen Ports
my $Port = $ObjDll->{_OpenPort}->Call();
# Lesen der NetId
my $Result = $ObjDll->{_LocalAddr}->Call(???);