Our new official repo is on github
LCD Smartie version 5.6 is released!
Download it now: https://github.com/LCD-Smartie/LCDSmartie/releases

Rivatuner plugin

Discussing issues that occur during plugin development.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo

Post Reply
thor2002ro
Posts: 13
Joined: August 7th, 2009, 3:43 pm

Rivatuner plugin

Post by thor2002ro »

Hi all
I'm trying to port a rivatuner plugin to lcd smartie (I'm not very good with VS ) from LCD Hype

after compiling it i get Access Violation displayed on the LCD

attachments contain my source + hype lcd plugin

please someone help!!! :smt006

Code: Select all

// Rivatuner_LCD
//

#include "stdafx.h"

#include <time.h>
#include <stdio.h>
#include <float.h>
#include <windows.h>

#include "RivaTuner.h"
#include "RTHMSharedMemory.h"

#define DLLEXPORT __declspec(dllexport)

typedef struct DATA { char data[65536]; } DATA, *LPDATA;

/*********************************************************
 *         SmartieInit                                   *
 *********************************************************/
extern "C" DLLEXPORT  void 
__stdcall  SmartieInit()
{
	// This function will be called when the plugin is 1st loaded.
	// This function is OPTIONAL.
}

/*********************************************************
 *         SmartieFini                                   *
 *********************************************************/
extern "C" DLLEXPORT  void 
__stdcall  SmartieFini()
{
	// This function will be called just before the plugin
	// is unloaded. This function is OPTIONAL.
}

/*********************************************************
 *         GetMinRefreshInterval                         *
 *********************************************************/
extern "C" DLLEXPORT  int
__stdcall  GetMinRefreshInterval()
{
	//
	// Define the minimum interval that a screen should get fresh
	// data from our plugin.
	// The actual value used by Smartie will be the higher of this
	// value and of the "dll check interval" setting
	// on the Misc tab.  [This function is optional, Smartie will
	// assume 300ms if it is not provided.]
	// 
	return 300; // 300 ms
}


/*********************************************************
 *         Function 1                                    *
 *  Simply returns "This is function 1"				     *
 *********************************************************/
extern "C" DLLEXPORT  DATA 
__stdcall  function1(char *param1,char *param2)
{
    DATA result;
	memset(&result, 0, sizeof(result));

	DWORD x0 = 5;
	DWORD x1 = 160;
	DWORD x2 = 210;
	DWORD y0 = 5;
	DWORD dy = 10;

	if (*param1 == '1')
	if (*param2 == '@')
	{
		char c;
		sscanf(param2, "%c,%d,%d,%d,%d,%d", &c, &x0, &x1, &x2, &y0, &dy);
	}

	HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "RTHMSharedMemory");

	if (hMapFile)
	{
		LPVOID pMapAddr = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);

		if (pMapAddr)
		{
			LPRTHM_SHARED_MEMORY_HEADER_V_1_0	lpHeaderV10	= (LPRTHM_SHARED_MEMORY_HEADER_V_1_0)pMapAddr;

			if (lpHeaderV10->dwSignature == 'RTHM')
				//check if we're connected to valid memory
			{
				DWORD dwSources = lpHeaderV10->dwNumEntries;
					//get number of data sources

				for (DWORD dwSource=0; dwSource<dwSources; dwSource++)
					//process each data source
				{
					if (lpHeaderV10->dwVersion == 0x10000)
						//we must use special handling code for shared memory v1.0, because entry size field (which is 
						//reuiqred for unified access to entries) was added to header in v1.1 only
					{
						LPRTHM_SHARED_MEMORY_ENTRY_V_1_0 lpEntry = (LPRTHM_SHARED_MEMORY_ENTRY_V_1_0)((LPBYTE)(lpHeaderV10 + 1) + dwSource * sizeof(RTHM_SHARED_MEMORY_ENTRY_V_1_0));
							//get ptr to  the current data source's entry

						if (*param2 == '@')
						{
							char szBuf[MAX_PATH];

							sprintf(szBuf, "%%Common.CreateNewLine(,%d,%d) '%s'", x0, y0, lpEntry->czSrc);
							strcat(result.data, szBuf);

							char szVal[MAX_PATH];
							if (lpEntry->data == FLT_MAX)
								strcpy(szVal, "N/A");
							else
								sprintf(szVal, "%.2f", lpEntry->data);

							sprintf(szBuf, "%%Common.CreateNewLine(,%d,%d) ': %s'", x1, y0, szVal);
							strcat(result.data, szBuf);

							if (lpEntry->data != FLT_MAX)
							{
								sprintf(szBuf, "%%Common.CreateNewLine(,%d,%d) '%s'", x2, y0, lpEntry->czDim);
								strcat(result.data, szBuf);
							}

							y0 += dy;
						}
						else
							if (!stricmp(param2, lpEntry->czSrc) && lpEntry->data != FLT_MAX)
								sprintf(result.data, "%.2f", lpEntry->data);
					}
					else
					{
						LPRTHM_SHARED_MEMORY_HEADER	lpHeader	= (LPRTHM_SHARED_MEMORY_HEADER)pMapAddr;
						LPRTHM_SHARED_MEMORY_ENTRY	lpEntry		= (LPRTHM_SHARED_MEMORY_ENTRY)((LPBYTE)(lpHeader + 1) + dwSource * lpHeader->dwEntrySize);

						if (*param2 == '@')
						{
							char szBuf[MAX_PATH];

							char szSrc[MAX_PATH];
							if (lpEntry->offset == 0.0f)
								strcpy(szSrc, lpEntry->czSrc);
							else
								sprintf(szSrc, "%s (%+.1f)", lpEntry->czSrc, lpEntry->offset);
							sprintf(szBuf, "%%Common.CreateNewLine(,%d,%d) '%s'", x0, y0, szSrc);
							strcat(result.data, szBuf);

							char szVal[MAX_PATH];
							if (lpEntry->data == FLT_MAX)
								strcpy(szVal, "N/A");
							else
								sprintf(szVal, "%.2f", lpEntry->dataTransformed + lpEntry->offset);

							sprintf(szBuf, "%%Common.CreateNewLine(,%d,%d) ': %s'", x1, y0, szVal);
							strcat(result.data, szBuf);

							if (lpEntry->data != FLT_MAX)
							{
								sprintf(szBuf, "%%Common.CreateNewLine(,%d,%d) '%s'", x2, y0, lpEntry->czDim);
								strcat(result.data, szBuf);
							}

							y0 += dy;
						}
						else
							if (!stricmp(param2, lpEntry->czSrc) && lpEntry->data != FLT_MAX)
								sprintf(result.data, "%.2f", lpEntry->dataTransformed + lpEntry->offset);
					}
				}
			}

			UnmapViewOfFile(pMapAddr);
		}

		CloseHandle(hMapFile);
	}

	return result;      
}


/*********************************************************
 *         Function 2                                    *
 *  Returns how many times the function has been called. *
 *********************************************************/
/*extern "C" DLLEXPORT  char * 
__stdcall  function2(char *param1, char *param2)
{
    static char outbuf[1000];
    static int count;
    
    count ++;
    
    itoa(count, outbuf, 10);
    return outbuf;       
}
*/
You do not have the required permissions to view the files attached to this post.

thor2002ro
Posts: 13
Joined: August 7th, 2009, 3:43 pm

Re: Rivatuner plugin

Post by thor2002ro »

NO ONE KNOWS VC++ ????

caesar
Forum Supporter
Posts: 734
Joined: October 15th, 2005, 10:39 am
Location: Romania
Contact:

Re: Rivatuner plugin

Post by caesar »

Too bloated for my taste.
Try some debugging tools, surely there must be some... make sure all dependencies are there, like dnbridge.dll

Post Reply