__declspec(dllimport) bool myTableCompare(myTable lhs, myTable rhs, myTable* output, unsigned int *count, double relative_tolerance, double absolute_tolerance) #### my $TableComparer = new Win32::API("myDll.dll","myTableCompare", 'NNPPDD','I','_cdecl'); #### $count = 1; $pointerToCount=pack('I',$count); $RelativeTol=0.001; $AbsTol=1.0; my $areTheSame=$TableComparer->Call($LeftTable,$RightTable,$packedOutputTable,$pointerToCount, $RelativeTol,$AbsTol); #### #! /usr/bin/perl use Win32::API; # Load the table creator from the dll. # C signature: __declspec(dllimport) myTable myTableCreate(); # typedef # struct myTable { # void* opaque; ///< Opaque pointer to storage # } myTable; $pass=1; my $CreateTable = new Win32::API("myDll.dll","HANDLE myTableCreate()"); if(not defined $CreateTable) { die "Can't import API myTableCreate(): $!\n"; } #Create empty tables. $pass = 1; if($pass) { my $LeftTable = $CreateTable->Call(); my $RightTable = $CreateTable->Call(); my $outputTable = $CreateTable->Call(); # Make sure that the function does return a memory position, and not a 0. $pass = $pass && ($LeftTable>0 && $RightTable>0); if($pass){print("Empty Tables Succesfully Created. Pass code: ".$pass.".\n");}; } # pack the table. if($pass) { my $packedLeftTable = pack('J',$LeftTable); my $packedRightTable = pack('J',$RightTable); my $packedOutputTable = pack('J',$outputTable); $pass = $pass && (unpack('J',$packedLeftTable) == $LeftTable && unpack('J',$packedRightTable) == $RightTable && unpack('J',$packedOutputTable) == $outputTable); if($pass){ print("Pack-Unpack round trip completed. Pass code: ".$pass."\n");} } # Path definition. my $pathTableLeft = 'C:/Temp/Requests/testTable1.TBL'; my $pathTableRight = 'C:/Temp/Requests/testTable2.TBL'; # Load the function. # Load the table file loader from the dll. # Some info about the API function: # __declspec(dllimport) enum cStatus myTableLoadFromFile(char const* filename, myTable* raw_result); # enum cStatus will treated as an int and interpreted using the array @DllTableStatus. my $LoadTableFromFile = new Win32::API("myDll.dll","myTableLoadFromFile", 'PP', 'I','_cdecl'); if(not defined $LoadTableFromFile) { die "Can't import API myTableLoadFromFile(): $!\n"; } if($pass) { my @DllTblStatus = ("OK Status, no errors", "Failed to allocate memory", "Unable to open or save file", "Unable to convert value to requested type", "Unknown error", "Validation Failed", "Cell could not be found"); my $isLoadedLeft = $LoadTableFromFile->Call($pathTableLeft,$packedLeftTable); my $isLoadedRight = $LoadTableFromFile->Call($pathTableRight, $packedRightTable); $pass = $pass && ($isLoadedLeft==0 && $isLoadedRight==0); if($pass) {print("Tables: ".$pathTableLeft." and ".$pathTableRight." loaded correctly. Pass code: ".$pass."\n");} else { if($isLoadedLeft>0){print("Loading table error on ".$pathTableLeft.": ".@DllTblStatus[$isLoadedLeft]."\n");} if($isLoadedRight>0){print("Loading table error on ".$pathTableRight.": ".@DllTblStatus[$isLoadedRight]."\n");} } }