📄 imgsample.cpp
字号:
#include <windows.h>
#include <stdio.h>
#include "ImgSample.h"
#include "..\Defines.h"
int g_ImgCount[4]={0,0,0,0};
int g_ImgIndex[4]={-1,-1,-1,-1};
char g_ErrorMsg[200][4]={"","","",""};
char g_IniFilePath[MAX_PATH]="";
BOOL APIENTRY DllMain(HANDLE hModule,DWORD dwReason,LPVOID lpReserved){
if (GetModuleFileName((HINSTANCE)hModule,g_IniFilePath,MAX_PATH)){
strcat(g_IniFilePath,".ini");
}
return TRUE;
}
BOOL ISInit(const int Channel){
char SectionName[10];
sprintf(SectionName,"Channel%d",Channel);
g_ImgCount[Channel]=GetPrivateProfileInt(SectionName,"Count",0,g_IniFilePath);
if (g_ImgCount[Channel]<=0){
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d file %s not found or ImgCount not correct!",Channel,g_IniFilePath);
return FALSE;
}
return TRUE;
}
BOOL ISGetImg(const int Channel,BYTE* pBmp){
if (g_ImgCount[Channel]<=0 || pBmp==NULL){
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d ImgCount not correct or memory myght not allocated!",Channel);
return FALSE;
}
g_ImgIndex[Channel]++;
if (g_ImgIndex[Channel]>=g_ImgCount[Channel]){
g_ImgIndex[Channel]=0;
}
char SectionName[10];
sprintf(SectionName,"Channel%d",Channel);
char ItemName[10];
sprintf(ItemName,"Img%d",g_ImgIndex[Channel]);
char strFileName[MAX_PATH];
if (GetPrivateProfileString(SectionName,ItemName,NULL,strFileName,MAX_PATH,g_IniFilePath)==0){
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d section %s not found or filename not correct!",Channel,SectionName);
return FALSE;
}
HANDLE hFile=CreateFile(strFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile==INVALID_HANDLE_VALUE){
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d open file %s error!",Channel,strFileName);
return FALSE;
}
DWORD nFileSize=GetFileSize(hFile,NULL);
if (nFileSize==INVALID_FILE_SIZE){
CloseHandle(hFile);
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d error to get size of file %s !",Channel,strFileName);
return FALSE;
}
if (nFileSize>MAX_BMP_SIZE){
CloseHandle(hFile);
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d file %s too large to read!",Channel,strFileName);
return FALSE;
}
DWORD dwRead;
if (ReadFile(hFile,pBmp,nFileSize,&dwRead,NULL)==0){
CloseHandle(hFile);
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d error when read file %s !",Channel,strFileName);
return FALSE;
}
if (dwRead!=nFileSize){
CloseHandle(hFile);
sprintf(g_ErrorMsg[Channel],"ImgSample: Channel %d read file %s size not correct!",Channel,strFileName);
return FALSE;
}
CloseHandle(hFile);
return TRUE;
}
LPCTSTR ISGetLastError(const int Channel){
return g_ErrorMsg[Channel];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -