All pastes #35498 Raw Edit

Anonymous

public text v1 · immutable
#35498 ·published 2006-01-02 07:09 UTC
rendered paste body
#include "sudoku.h"

int __declspec(dllexport) InitSudokuDLL()
{
	//load the dll
	hDll = LoadLibrary("C:\\theDLLplace\\suo_11_eng.dll");

	//error checking
	if (hDll == NULL)
		return -1;

	//set the functions
	Solve = (FPTR_Solve)GetProcAddress(hDll, "Solve");
	Generate = (FPTR_Generate)GetProcAddress(hDll, "Generate");
	GetNodesSearched = (FPTR_GetNodesSearched)GetProcAddress(hDll, "GetNodesSearched");
	GetFirstSolution = (FPTR_GetFirstSolution)GetProcAddress(hDll, "GetFirstSolution");
	GetFirstSolDepth = (FPTR_GetFirstSolDepth)GetProcAddress(hDll, "GetFirstSolDepth");
	GetFirstSolNodes = (FPTR_GetFirstSolNodes)GetProcAddress(hDll, "GetFirstSolNodes");
	GetProcessingTime = (FPTR_GetProcessingTime)GetProcAddress(hDll, "GetProcessingTime");
	HintX = (FPTR_HintX)GetProcAddress(hDll, "HintX");
	SetLevels = (FPTR_SetLevels)GetProcAddress(hDll, "SetLevels");

	//seed the random number generator
	srand( (unsigned)time( NULL ) );

	return 1;
}

int __declspec(dllexport) DestroySudokuDLL()
{
	//unload the dll
	FreeLibrary(hDll);

	//delete the arrays
	delete[] mPuzzle;
	delete[] mOrig;
	delete[] mWholeBoard;

	return 1;
}

int __declspec(dllexport) GeneratePuzzle(int diff, int diffMin, int diffMax, int diag, int symetric)
{	
	//generate the puzzle and store it
	Generate((int*)mPuzzle, diff, diffMin, diffMax, diag, symetric);
	
	//keep the original seperate
	for(int i = 0; i < 9; i++)
	{
		for(int a = 0; a < 9; a++)
		{
			mOrig[i][a] = mPuzzle[i][a];
			mWholeBoard[i][a] = mPuzzle[i][a];
		}
	}
	
	//get the entire board
	Solve(false, false, diag, diff, (int*)mWholeBoard);

	return 1;
}

int __declspec(dllexport) SolvePuzzle(int guessOnly, int noGuess, int diag, int diff)
{
	//copy the puzzle
	for(int i = 0; i < 9; i++)
	{
		for(int a = 0; a < 9; a++)
		{
			mWholeBoard[i][a] = mPuzzle[i][a];
		}
	}

	//solve it
	Solve(false, false, diag, 3, (int*)mWholeBoard);

	return 1;
}

int __declspec(dllexport) SetDiffLevels(SAFEARRAY specs)
{
	int* temp;
    temp = (int*)(specs.pvData);

	return SetLevels(temp);
}

int __declspec(dllexport) HintShowRand(int* row, int* col, int* val)
{
	*row = (rand() % 9) + 1;
	*col = (rand() % 9) + 1;

	*val = mWholeBoard[*row][*col];

	return 1;
}