home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!darwin.sura.net!news.udel.edu!bach.udel.edu!radel
- From: radel@bach.udel.edu (Todd Radel)
- Subject: ACK! Problem with GlobalDosAlloc() !!!!!
- Message-ID: <Bs31o2.52J@news.udel.edu>
- Sender: usenet@news.udel.edu
- Nntp-Posting-Host: bach.udel.edu
- Organization: University of Delaware
- Date: Tue, 28 Jul 1992 04:55:13 GMT
- Lines: 93
-
- Earlier, I asked the net how to use the DPMI Function "Allocate Global
- DOS Memory" to communicate between a Windows client in 386Enh mode and
- a DOS box. Someone suggested I use GlobalDosAlloc() instead. I wrote
- the following two snippets of code: "DPMI Server" is the Windows
- program, which allocates a 4K block of memory and writes the segment
- of the block to a file (so the client can find the segment); "DPMI
- Client" is the DOS program, which reads the segment from the file,
- makes a pointer to it, and looks for the handshake flag (42!) so I
- know the connection is OK.
-
- But the DOS client gets stuck in an endless loop, looking for a
- handshake which is never going to come: it prints "Waiting for
- handshake, ready=29555" over and over. Clearly, it's not looking
- at the same area of memory that the Windows program is.
-
- Could some kind soul look this over and e-mail me corrections? I'm
- stuck in the middle of a project!!!
-
- If it helps, "tagDMA" is defined as follows:
-
- struct point
- {
- unsigned char x, y;
- };
-
- struct tagDMA
- {
- unsigned int ready;
- unsigned int npts;
- point data[2046];
- };
-
- Here's the code fragments:
-
-
- ----------------------------- DPMI Server -------------------------------------
- void TMyApp::InitMainWindow()
- {
- DWORD shmHandle;
- tagDMA far* DMAbuffer;
-
- MainWindow = new TMyWindow(NULL, Name);
- if ((shmHandle = GlobalDosAlloc (4096)) == 0)
- {
- MessageBox (MainWindow->HWindow, "Could not allocate global DOS memory.", "SLPhone", MB_ICONSTOP);
- exit(1);
- }
- DWORD shmSeg = (shmHandle & 0xFFFF0000L) >> 16;
- DWORD shmSel = (shmHandle & 0x0000FFFFL);
- DMAbuffer = (tagDMA far*) MK_FP (shmSel, 0x0000);
-
- // Send "ready to begin" code to client:
- DMAbuffer->ready = 42;
-
- / Write the pointer to a file so the client can find it:
- FILE *fptr = fopen ("c:\\address.dat", "wb");
- fwrite (&shmSeg, sizeof(DWORD), 1, fptr);
- // Also print some diagnostic info.:
- fprintf (fptr, "segment = %Fp, selector = %Fp\n", shmSeg, shmSel);
- fclose (fptr);
- }
-
- ----------------------------- DPMI Client ------------------------------------
- main()
- {
- // Read the pointer from the filr:
- fptr = fopen ("c:\\address.dat", "rb");
- fread (&shmSeg, 4, 1, fptr);
- fgets (buf, 80, fptr);
- fclose (fptr);
-
- DMAbuffer = (tagDMA far*) MK_FP (shmSeg, 0x0000);
- printf ("Using DMA buffer at %Fp\n", DMAbuffer);
- printf ("Important note: %s\n", buf);
-
- // Wait for handshake:
- while (DMAbuffer->ready != 42)
- if (kbhit())
- exit(3);
- else
- printf ("Waiting for handshake, ready=%d ...\r", DMAbuffer->ready);
- DMAbuffer->ready = 0;
- printf ("Shutting down! \r");
- printf ("\n\n\n");
- return 0;
- }
-
-
- --
- Todd Radel | "I obscenity in the milk of all," Agustin said,
- CIS/English undergrad | "if it does not seem like a lunatic asylum in
- University of Delaware | here." -- Hemingway, _For Whom the Bell Tolls_
- A.I. duPont Institute, 1600 Rockland Road, Wilmington, DE 19899
-