Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4996)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <windows.h></windows.h>
Shinya Kitaoka d4642c
#include <stdlib.h></stdlib.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttwain_state.h"
Toshihiro Shimizu 890ddd
#include "ttwainP.h"
Toshihiro Shimizu 890ddd
#include "ttwain_statePD.h"
Toshihiro Shimizu 890ddd
#include "ttwain_util.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static void *hDSMLib; /* handle of DSM */
Toshihiro Shimizu 890ddd
extern void TTWAIN_SetState(TWAINSTATE status);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TTWAIN_LoadSourceManagerPD(void)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	char winDir[_MAX_PATH];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TTWAIN_GetState() >= TWAIN_SM_LOADED)
Toshihiro Shimizu 890ddd
		return TRUE; /* DSM already loaded */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	GetWindowsDirectory(winDir, _MAX_PATH);
Toshihiro Shimizu 890ddd
	if (!winDir[0])
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	strcat(winDir, "\\");
Toshihiro Shimizu 890ddd
	strcat(winDir, DSM_FILENAME);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	hDSMLib = LoadLibrary(winDir);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
if (tnz_access(winDir, 0x00) != -1)
Toshihiro Shimizu 890ddd
  hDSMLib = LoadLibrary(winDir);
Toshihiro Shimizu 890ddd
else
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  hDSMLib = 0;
Toshihiro Shimizu 890ddd
  return FALSE;
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (hDSMLib) {
Toshihiro Shimizu 890ddd
		TTwainData.DSM_Entry = (DSMENTRYPROC)GetProcAddress(hDSMLib, DSM_ENTRYPOINT);
Toshihiro Shimizu 890ddd
		if (TTwainData.DSM_Entry) {
Toshihiro Shimizu 890ddd
			TTWAIN_SetAvailable(AVAIABLE_YES);
Toshihiro Shimizu 890ddd
			TTWAIN_SetState(TWAIN_SM_LOADED);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			FreeLibrary(hDSMLib);
Toshihiro Shimizu 890ddd
			hDSMLib = NULL;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		TTwainData.DSM_Entry = 0;
Toshihiro Shimizu 890ddd
	return (TTWAIN_GetState() >= TWAIN_SM_LOADED);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_UnloadSourceManagerPD(void)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TTWAIN_GetState() == TWAIN_SM_LOADED) {
Toshihiro Shimizu 890ddd
		if (hDSMLib) {
Toshihiro Shimizu 890ddd
			FreeLibrary(hDSMLib);
Toshihiro Shimizu 890ddd
			hDSMLib = NULL;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		TTwainData.DSM_Entry = NULL;
Toshihiro Shimizu 890ddd
		TTWAIN_SetState(TWAIN_PRESESSION);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return (TTWAIN_GetState() == TWAIN_PRESESSION);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif