在执行源管理时出现的问题!
我用的是非界面的程序来写TWAIN接口.下面是我刚开始的一些代码,从twain官方网站上下的twain1.9a 文档里的整理的一些代码来实现源管理的装载和打开,编译能通过,但在调试时,到打开源管理时就会出现一个"访问违法"的错误.我怀疑是源管理装载出了问题,但又不知道怎么判断源管理是否成功装载.
//下面是附上我的代码,代码写得很简单,麻烦你给我看看
#include "windows.h"
#include "ver.h"
#include "stdio.h"
#include "twain.h"
void main()
{
DSMENTRYPROC pDSM_Entry;
HMODULE hDSMLib;
char szSMDir[144];
OFSTRUCT of;
TW_IDENTITY AppID; // App's identity structure
TW_HANDLE hWnd ;
TW_UINT16 rc;
// check for the existence of the TWAIN_32.DLL file in the Windows
// directory
GetWindowsDirectory (szSMDir, sizeof(szSMDir));
/*** Could have been networked drive with trailing '\' ***/
if (szSMDir [(lstrlen (szSMDir) - 1)] != '\\')
{ lstrcat( szSMDir, "\\" );
}
if (OpenFile(szSMDir, &of, OF_EXIST) != -1)
{
// load the DLL
if ((hDSMLib = LoadLibrary("TWAIN_32.DLL")) != NULL)
{
// check if library was loaded
if(hDSMLib)
{
if ((pDSM_Entry = (DSMENTRYPROC)GetProcAddress(hDSMLib,
MAKEINTRESOURCE (1))) != NULL)
{
if (pDSM_Entry )
FreeLibrary(hDSMLib);
}
}
}
}
///////////*********打开源管理*********************/////////
AppID.Id = 0; // Initialize to 0 (Source Manager
// will assign real value)
AppID.Version.MajorNum = 3; //Your app's version number
AppID.Version.MinorNum = 5;
AppID.Version.Language = TWLG_ENGLISH_USA;
AppID.Version.Country = TWCY_USA;
lstrcpy (AppID.Version.Info, "Your App's Version String");
AppID.ProtocolMajor = TWON_PROTOCOLMAJOR;
AppID.ProtocolMinor = TWON_PROTOCOLMINOR;
AppID.SupportedGroups = DG_IMAGE ¦ DG_CONTROL;
lstrcpy (AppID.Manufacturer, "App's Manufacturer");
lstrcpy (AppID.ProductFamily, "App's Product Family");
lstrcpy (AppID.ProductName, "Specific App Product Name");
//////////////执行DG_CONTROL / DAT_PARENT / MSG_OPENDSM
hWnd = (TW_HANDLE)GetActiveWindow();
rc = (*pDSM_Entry) (&AppID,
NULL,
DG_CONTROL,
DAT_PARENT,
MSG_OPENDSM,
(TW_MEMREF) &hWnd);
}