Dear List Thanks to everybody who responded to my query regarding C code.
Two members, Bill Thoen and Tony at English Nature suggested making all longs explicit eg 0L and 2L etc. I tried this but it made no difference. Two other members, Warren Vick and Kris Woodland, said that they tried the code and it worked. Therefore they suggested perhaps I had some string values that overwrite lsString[100] ie more than 100 characters. However the code "as is" goes wrong with my Microsoft compiler ( Version 6.0 ). ( In the original version lsString is actually 200 bytes and is never set longer than that ). I enclose the code again, but this time I have the longs explicit and also this time I have included the DLLExport etc for use with MapBasic. ( The version I enclosed earlier was for calls from VB - this one is for calls from MapBasic ). I have enclosed some simple MapBasic code to call the DLL. I would be really keen to know the compiler settings, Warren and Kris are using when they have the code running. I am using all the Microsoft defaults. I have also now included some mapbasic code to test the compiled DLL ( This assumes the compiled DLL is copied to the root of Drive C ) for anyone else who might test the code. The solution must be in these compiler settings !!??!! The original code was much larger than this, and it was quite tricky to narrow down the code to these twelve lines or so and maintain the problem! Slight amendments allow the code to work, but I need the original like it was and thus need this precise code to work as is. Warren thought that perhaps there were other functions in the DLL interfering, but the version here ( and the earlier version ) are the complete DLL and it goes wrong every time in both VB ( as long ) and in MapBasic as BYOUT(long) ie with DLLExport etc. The reason I only have this routine in the DLL is that the original code was in a large EXE so I have now isolated the problem to just twelve lines of code or so, in an isolated DLL. Its as if the compiler optimiser thinks the while statement does not make use of jCount. If code is included to test the value of jCount the code runs OK ( ie bug disappears) ! However the WHILE statement actually tests jCount and it would appear it stays as 0 in code included. If the else condition lnThreshold = 1L is removed the code runs OK and yet this code should never get called as lnOranges is always > 1. If either strcpy(lsString,"string"); OR lnApple[jCount] = 0; are commented out again the code will run. The interaction of all the lines seems to cause the bug. Any help very very greatfully received!! I have sent the code to Microsoft support. It would be great if the MapInfo community could solve this first! Regards Bob HERE IS THE C CODE (with explicit longs OL etc) and MapBasic calls #include <stdlib.h> #include <string.h> #define BYOUT(returntype) __declspec(dllexport) returntype __cdecl BYOUT(long) Example1() { long iFlag = 0L; long lnOranges = 0L; long lnApple[100]; long jCount = 0L; long lnThreshold = 0L; char lsString[100]; lnOranges = 2L; lnThreshold = 1L; for (iFlag = 0L; iFlag < 2L;iFlag++) { if (lnOranges> 1L) { jCount = 0L; while (jCount < lnThreshold) { strcpy(lsString,"string"); lnApple[jCount] = 0; jCount++; } } else { lnThreshold = 1L; } } return 73; } HERE IS SIMPLE MAPBASIC CODE TO CALL THE DLL PROVIDED IT IS IN ROOT OF DRIVE C Declare Sub Main Declare Sub CallBug Declare Function Example1 lib "c:\bugA.dll" () as integer Sub Main Create Menu "Bob" as "Bug" calling CallBug Alter Menu Bar add "Bob" End Sub Sub CallBug dim lnLong as integer lnLong = Example1() print "Returned " + lnLong End Sub ====END CODE==== If line(s) are commented out ( eg lnApple[jCount] = 0 ) to allow code to run the MapBasic program prints 73. However the code as is never returns and from other debugging I am convinced the Microsoft compiler is not incrementing jCount within the while loop with code as is. There seem to be no string overruns, and no use of pointers - the normal cause of such very frustrating problems. Fingers crossed !!! Bob -- bob young --------------------------------------------------------------------- List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Message number: 18192