Mapfile example of my problem
I can not read the data exchanged pass the first Index of the Arrayed UDT
As can be seen by the code execution the aZooKeeper() array of ZooType has the data
but the Mapfile only delivers data from Zoo Index 1
Example of the problem is demo-ed in the code below
Thank you for any help
Bruce
I can not read the data exchanged pass the first Index of the Arrayed UDT
As can be seen by the code execution the aZooKeeper() array of ZooType has the data
but the Mapfile only delivers data from Zoo Index 1
Example of the problem is demo-ed in the code below
Thank you for any help
Code:
' ' Mapfile example of my problem ' ' I can not read the data exchanged pass the first Index of the Arrayed UDT ' ' As can be seen by the code execution the aZooKeeper() array of ZooType has the data ' but the Mapfile only delivers data from Zoo Index 1 ' ' ' Change the %Send=-1 to compile the send file ' %Recv=-1 to compile the Recv file ' ' Please don't do both I'm not check for that right now ' ' The code is set for %Send=-1 now ' ' ******************************************************************** ' ' The Send will add a new zoo entry on each [return] ' ' 5 (Index2 1-5) for Index=1 for Boston ' 5 (Index2 1-5) for Index=2 For Omaha ' ' You can see the entry value after each action ' ' It will then enter "Zoo Index and Animal Index " Cycle so you can see the results that the Recv side should display ' ' Entering a 0 or CR will terminate the either program at this stage ' ' The Recv program goes directly into the "Zoo Index ..." section ' ' If you enter the Zoo Index and Animal Index as the sender shows you SHOULD get the smae display....... ' ' Well, there lays the problem. ' ' The recv program can only access Zoo index 1 and it's Animal Indexs 1-5 ' ' NO part of Zoo index 2 is available! ' ' I don't know why. ' ' If you can help I thank you in advance ' ' ' ' ' ' The proper code to correct this would be appreciated ' ' Thank You ' ' ' Bruce Wood ' #COMPILER PBCC 4, PBCC 5 ' I think it will work with PBCC 5 %Send=-1 %Recv=0 ' Set to -1 to Select the proper file generation #IF %Send #COMPILE EXE "MapFile Send" #ELSE #COMPILE EXE "MapFile Recv" #ENDIF #DIM ALL #CONSOLE ON #INCLUDE "Win32api.inc" $MapFileName="SimpleZooMap" ' Simple ha I thought so %MaxZoos=50 ' Max Zoos %MaxUnits=50 %MaxZooNameLen=50 %MaxAnimalNameLen=10 %MaxBuildingNameLen=36 %MaxBuildingUnitIDLen=36 %MaxCageIDLen=36 TYPE ZooType WORD uZooName AS ASCIIZ * %MaxZooNameLen uAnimalName(%MaxUnits) AS ASCIIZ * %MaxAnimalNameLen uAnimalID(%MaxUnits) AS LONG uBuildingName(%MaxUnits) AS ASCIIZ * %MaxBuildingNameLen uBuildUnitID(%MaxUnits) AS ASCIIZ * %MaxBuildingUnitIDLen uCageID(%MaxUnits) AS LONG END TYPE %ZooTypeSize=4640 ' I know it's a static... but the Dim AT demands a Constant ' **************************************************************************************** FUNCTION PBMAIN () AS LONG LOCAL RetError,Results,a AS STRING LOCAL Index,Index2 AS LONG DIM MapFileHandle AS GLOBAL LONG DIM MkMapViewAddress AS ZooType PTR ' LOCAL Junk AS LONG DIM MapSize AS GLOBAL LONG ' yes I want the Array to be Base 1 DIM aZooKeeper(1 TO %MaxZoos) AS GLOBAL ZooType ' *********************************** ' Junk=SIZEOF(ZooType) MapSize=SIZEOF(ZooType)*%MaxZoos ' Size of the memory map request Sizeof the Type * %MaxZoos aZooKeeper has a count of Test count of 50... ' Make Mapfile CALL MakeMapFile TO MkMapViewAddress IF ISTRUE MkMapViewAddress THEN aZooKeeper(1)[email protected] ' We have our View Address ELSE PRINT "Error on create or view map" END IF ' Lets test the Zoo additions #IF %Send ' Index 1 Series RetError=AssociateZoo("Boston","Cat",1,"BigCats",1) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Boston","Dog",1,"BigDogs",2) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Boston","Fish",1,"SmallFish",3) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Boston","Bird",1,"BirdHouse",4) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Boston","Buffalo",1,"Grazers",5) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION ' This will make Incr Index to 2 .. It's a Different Zoo RetError=AssociateZoo("Omaha","Elephant",1,"MegaFona",1) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Omaha","Monkey",1,"Monkey",2) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Omaha","Ape",1,"Primate",3) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Omaha","Falcon",1,"Birds of Prey",4) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION RetError=AssociateZoo("Omaha","Kangaroo",1,"Marsupial",5) IF LEFT$(RetError,1)="~" THEN CALL PrintError(RetError) : EXIT FUNCTION ' Now give the changes to the common map file @MkMapViewAddress=aZooKeeper(1) ' try this CALL CloseView(MkMapViewAddress) ' I believe I need to close the View before the other party can read the file #ENDIF PRINT Index=1 DO UNTIL Index=0 INPUT "Zoo Index and Animal Index " Index,Index2 IF Index <=0 OR Index > %MaxZoos OR Index2 <=0 OR Index2 > %MaxUnits THEN ITERATE DO RetError=GetAssociateInfo(Index,Index2) LOOP #IF %RECV CALL CloseView(MkMapViewAddress) ' I believe I need to close the View before the other party can read the file #ENDIF CALL CloseMap(MapFileHandle) END FUNCTION ' ******************************************************************** SUB PrintError ALIAS "PrintError"(BYVAL ErrorMsg AS STRING) PRINT "AssociateZoo reported this error " & ErrorMSG END SUB ' ******************************************************************** FUNCTION AssociateZoo ALIAS "AssociateZoo"(pZoo AS ASCIIZ,pAnimalName AS ASCIIZ,BYVAL pAnimalID AS LONG,pBuildingName AS ASCIIZ,BYVAL pCageID AS LONG) EXPORT AS STRING LOCAL Index,Index2 AS LONG LOCAL Length AS LONG LOCAL Results AS STRING REDIM atZoo(1 TO %MaxZoos) AS STRING * %ZooTypeSize AT VARPTR(aZooKeeper(1)) ARRAY SCAN atZoo(), COLLATE UCASE, FROM 1 TO LEN(pZoo), = UCASE$(pZoo), TO Index IF ISFALSE Index THEN ARRAY SCAN atZoo(), FROM 1 TO 1, = $NUL, TO Index IF ISTRUE Index THEN aZooKeeper(Index).uZooName=pZoo ELSE FUNCTION="~Zoo Storage is full" : EXIT FUNCTION END IF END IF ' We have the Zoo storage index REDIM atAnimalName(1 TO %MaxZoos) AS STRING * %MaxAnimalNameLen AT VARPTR(aZooKeeper(Index).uAnimalName(1)) ARRAY SCAN atAnimalName(), COLLATE UCASE, FROM 1 TO LEN(pAnimalName), = UCASE$(pAnimalName), TO Index2 IF ISFALSE Index2 THEN ARRAY SCAN atAnimalName(),FROM 1 TO 1, = $NUL, TO Index2 IF ISTRUE Index2 THEN aZooKeeper(Index).uAnimalName(Index2)=pAnimalName ELSE FUNCTION="~ " & pZoo & " has the maximum animals associated with it" : EXIT FUNCTION END IF END IF ERASE atAnimalName(),atZoo() ' ok push the other item into place aZooKeeper(Index).uAnimalID(Index2)=pAnimalID aZooKeeper(Index).uBuildingName(Index2)=pBuildingName aZooKeeper(Index).uCageID(Index2)=pCageID Results=FORMAT$(Index) & "," & FORMAT$(Index2) PRINT : PRINT "Zoo Name " aZooKeeper(Index).uZooName ? "Animal Name " aZooKeeper(Index).uAnimalName(Index2) ? "Animal ID " aZooKeeper(Index).uAnimalID(Index2) ? "Building Name " aZooKeeper(Index).uBuildingName(Index2) ? "Cage ID " aZooKeeper(Index).uCageID(Index2) ? "Zoo Index " Index ? "Animal Index " Index2 ? "Results returned " Results PRINT WAITKEY$ FUNCTION=Results END FUNCTION ' **************************************************************** FUNCTION GetAssociateInfo ALIAS "GetAssociateInfo"(BYVAL Index AS LONG,BYVAL Index2 AS LONG) EXPORT AS STRING LOCAL Results AS STRING PRINT : PRINT "Zoo Name " aZooKeeper(Index).uZooName ? "Animal Name " aZooKeeper(Index).uAnimalName(Index2) ? "Animal ID " aZooKeeper(Index).uAnimalID(Index2) ? "Building Name " aZooKeeper(Index).uBuildingName(Index2) ? "Cage ID " aZooKeeper(Index).uCageID(Index2) ? "Zoo Index " Index ? "Animal Index " Index2 PRINT FUNCTION="" END FUNCTION ' **************************************************************************************** FUNCTION MakeMapFile ALIAS "MakeMapFile" EXPORT AS LONG LOCAL MkMapViewAddress AS LONG MapFileHandle = CreateFileMapping(BYVAL -1, BYVAL 0, BYVAL %PAGE_READWRITE, BYVAL 0, MapSize, $MapFileName) IF ISTRUE MapFileHandle OR ( MapFileHandle = 0 AND GetLastError = %ERROR_ALREADY_EXISTS ) THEN MkMapViewAddress = MapViewOfFile(MapFileHandle, %FILE_MAP_ALL_ACCESS, 0, 0, 0) FUNCTION=MkMapViewAddress ELSE FUNCTION=%False ' Flag create mapping file error END IF END FUNCTION ' **************************************************************************************** FUNCTION MakeView ALIAS "MakeView" EXPORT AS LONG LOCAL MkMapViewAddress AS LONG MkMapViewAddress = MapViewOfFile(MapFileHandle, %FILE_MAP_ALL_ACCESS, 0, 0, 0) FUNCTION=MkMapViewAddress END FUNCTION SUB CloseView ALIAS "CloseView" (BYVAL ViewAddress AS LONG) EXPORT UnmapViewofFile BYVAL ViewAddress END SUB ' **************************************************************************************** SUB CloseMap ALIAS "CloseMap" (BYVAL MapHandle AS LONG) EXPORT IF ISTRUE MapFileHandle THEN CloseHandle MapFileHandle END SUB
Bruce
Comment