home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / mswindo / programm / misc / 1040 < prev    next >
Encoding:
Text File  |  1992-07-27  |  3.3 KB  |  105 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!darwin.sura.net!news.udel.edu!bach.udel.edu!radel
  3. From: radel@bach.udel.edu (Todd Radel)
  4. Subject: ACK! Problem with GlobalDosAlloc() !!!!!
  5. Message-ID: <Bs31o2.52J@news.udel.edu>
  6. Sender: usenet@news.udel.edu
  7. Nntp-Posting-Host: bach.udel.edu
  8. Organization: University of Delaware
  9. Date: Tue, 28 Jul 1992 04:55:13 GMT
  10. Lines: 93
  11.  
  12. Earlier, I asked the net how to use the DPMI Function "Allocate Global
  13. DOS Memory" to communicate between a Windows client in 386Enh mode and
  14. a DOS box.  Someone suggested I use GlobalDosAlloc() instead.  I wrote
  15. the following two snippets of code:  "DPMI Server" is the Windows
  16. program, which allocates a 4K block of memory and writes the segment
  17. of the block to a file (so the client can find the segment); "DPMI
  18. Client" is the DOS program, which reads the segment from the file,
  19. makes a pointer to it, and looks for the handshake flag (42!) so I
  20. know the connection is OK.
  21.  
  22. But the DOS client gets stuck in an endless loop, looking for a
  23. handshake which is never going to come:  it prints "Waiting for
  24. handshake, ready=29555" over and over.  Clearly, it's not looking
  25. at the same area of memory that the Windows program is.
  26.  
  27. Could some kind soul look this over and e-mail me corrections?  I'm
  28. stuck in the middle of a project!!!
  29.  
  30. If it helps, "tagDMA" is defined as follows:
  31.  
  32. struct point
  33. {
  34.   unsigned char x, y;
  35. };
  36.  
  37. struct tagDMA
  38. {
  39.   unsigned int ready;
  40.   unsigned int npts;
  41.   point data[2046];
  42. };
  43.  
  44. Here's the code fragments:
  45.  
  46.  
  47. ----------------------------- DPMI Server -------------------------------------
  48. void TMyApp::InitMainWindow()
  49. {
  50.   DWORD shmHandle;
  51.   tagDMA far* DMAbuffer;
  52.  
  53.   MainWindow = new TMyWindow(NULL, Name);
  54.   if ((shmHandle = GlobalDosAlloc (4096)) == 0)
  55.     {
  56.       MessageBox (MainWindow->HWindow, "Could not allocate global DOS memory.", "SLPhone", MB_ICONSTOP);
  57.       exit(1);
  58.     }
  59.   DWORD shmSeg = (shmHandle & 0xFFFF0000L) >> 16;
  60.   DWORD shmSel = (shmHandle & 0x0000FFFFL);
  61.   DMAbuffer = (tagDMA far*) MK_FP (shmSel, 0x0000);
  62.  
  63.   // Send "ready to begin" code to client:
  64.   DMAbuffer->ready = 42;
  65.  
  66.   / Write the pointer to a file so the client can find it:
  67.   FILE *fptr = fopen ("c:\\address.dat", "wb");
  68.   fwrite (&shmSeg, sizeof(DWORD), 1, fptr);
  69.   // Also print some diagnostic info.:
  70.   fprintf (fptr, "segment = %Fp, selector = %Fp\n", shmSeg, shmSel);
  71.   fclose (fptr);
  72. }
  73.  
  74. ----------------------------- DPMI Client ------------------------------------
  75. main()
  76. {
  77.   // Read the pointer from the filr:
  78.   fptr = fopen ("c:\\address.dat", "rb");
  79.   fread (&shmSeg, 4, 1, fptr);
  80.   fgets (buf, 80, fptr);
  81.   fclose (fptr);
  82.  
  83.   DMAbuffer = (tagDMA far*) MK_FP (shmSeg, 0x0000);
  84.   printf ("Using DMA buffer at %Fp\n", DMAbuffer);
  85.   printf ("Important note: %s\n", buf);
  86.  
  87.   // Wait for handshake:
  88.   while (DMAbuffer->ready != 42)
  89.     if (kbhit())
  90.       exit(3);
  91.     else
  92.       printf ("Waiting for handshake, ready=%d ...\r", DMAbuffer->ready);
  93.   DMAbuffer->ready = 0;
  94.   printf ("Shutting down!     \r");
  95.   printf ("\n\n\n");
  96.   return 0;
  97. }
  98.  
  99.  
  100. -- 
  101. Todd Radel                   | "I obscenity in the milk of all," Agustin said,
  102. CIS/English undergrad        | "if it does not seem like a lunatic asylum in
  103. University of Delaware       | here." -- Hemingway, _For Whom the Bell Tolls_
  104. A.I. duPont Institute, 1600 Rockland Road, Wilmington, DE  19899
  105.