In the XMS module, the global variable int nAfxXmsStyle is the variable that controls the default XMS memory allocation mode.
nAfxXmsStyle = 0 (=XMSMEMORY_STYLE_MORAL) means default XMS
nAfxXmsStyle = 1 (=XMSMEMORY_STYLE_DISK) means disk XMS
nAfxXmsStyle = 2 (=XMSMEMORY_STYLE_EMSCARD) means the extended memory card of PCM3486
If you call the "InitSystem()" function, it will analyze the "XmsStyle" key in the "Boot" section of the "Config.Sys" file.
Actually, you can call CXmsMemory::SetXmsStyle() to change the XMS property, and it must be called before the following functions:
CXmsMemory::SetSize()
CXmsMemory::SetSizeEx()
CXmsMemory::MallocXms() function
//---------------------------------------------
#include <string.h>
#include <Symbol.h>
#include <Memory.h>
extern unsigned _stklen = 50L * 1024L;
extern int nAfxXmsStyle;
int main()
{
nAfxXmsStyle = XMSMEMORY_STYLE_DISK; // Use disk emulated XMS memory
// Create a default frame with 256 bytes
CXmsMemory mXmsMemory;
// Allocate a new memory block as a new frame. The larger the frame, the faster the access to XMS
BYTE* pNewBlock = new BYTE[2048];
// The user's default frame is 256 bytes, change the frame to 2048 bytes
BYTE* pOldBlock = mXmsMemory.ChangeFrame(pNewBlock, 2048);
// Delete the old frame
delete pOldBlock;
// Allocate 200K bytes of XMS memory
mXmsMemory.SetSize(200L, 1024L);
// Increase 100K of XMS memory (300 = 200 + 100)
mXmsMemory.SetSizeEx(300L, 1024L);
// Write the string "My name is LiPing1!" to the position with byte-based index "120030L"
char buf[100] = "My Name is LiPing1!";
mXmsMemory.SetByteData(120030L, (BYTE *)buf, _fstrlen(buf) + 1);
// Read the string "My name is LiPing1!" from the position with byte-based index "120030L"
_fmemset((BYTE *)buf, 0, 100);
mXmsMemory.GetByteData(120030L, (BYTE *)buf, 100);
printf("\n S = \"%s\"", buf);
// If running on an ordinary PC, you can change the memory to XMS
mXmsMemroy.FreeXms();
mXmsMemory.SetXmsStyle(XMSMEMORY_STYLE_NORMAL); // If it is PCM3486, change to XMSMEMORY_STYLE_EMSCARD
mXmsMemory.SetSize(300L, 1024L);
// Write the string "My name is LiPing2!" to the position with byte-based index "120030L"
_fmemcpy(buf, "My Name is LiPing2!");
mXmsMemory.SetByteData(120030L, (BYTE *)buf, _fstrlen(buf) + 1);
// Read the string "My name is LiPing2!" from the position with byte-based index "120030L"
_fmemset((BYTE *)buf, 0, 100);
mXmsMemory.GetByteData(120030L, (BYTE *)buf, 100);
printf("\n S = \"%s\"", buf);
getch();
// Release the allocated XMS memory block
mXmsMemory.FreeXms();
return(0);
}