When my code (below) is executed, a error message is triggered which says "The operation completed successfully." To give this some context, hFileMap is valid; I have checked this with my debugger, and other operations can easily be performed correctly on this handle that yield correct results. The only weird thing is that MapViewOfFile returns a null pointer. Since I use this memory mapped file as a way of communicating between two applications, this function is critical. Please note that I am no beginner to coding, and this same program successfully implements multi-threading as well as on-the-fly (dynamic) function creation (also called reflection) for its scripting engine.

static char *Buff = NULL;
	static HANDLE hFileMap;
	int jointCount = 0;
	int startingBone = msModel_GetBoneCount(pModel);

	msBone *currentBone = NULL;

	

	UINT_PTR threadId;
	int value = 10;

	hFileMap = OpenFileMapping(PAGE_READONLY, true, "animationMemFileClientOut");
	if (hFileMap == NULL)
	{
		msModel_Destroy(pModel);
		return 0;
	}

	char* buffer = (char *)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);

	if (buffer == NULL)
	{
		DWORD pMessage = GetLastError();

		buffer = new char[128];

		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
                       (LPCVOID)pMessage, 
                       0,
                       0,
                       buffer, 
                       128, 
                       NULL);
		MessageBox(NULL, (LPCSTR)buffer, "Error", MB_OK);
	}

>> a error message is triggered which says "The operation completed successfully."

This happens because you are using FormatMessage() incorrectly.

See Retrieving the Last-Error Code. Note how the value returned by GetLastError() is passed to FormatMessage() .

And to fix the error, make this change: hFileMap = OpenFileMapping( /*PAGE_READONLY*/ FILE_MAP_READ, true, "animationMemFileClientOut");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.