📄 myvc.cpp
字号:
VFIT * pSem;
char msg[TXT_LEN], key[20];
int index;
HANDLE hlock; //共享锁
//等待共享文件被释放,然后抢占并琐定
hlock = WaitLock(MUTEX_VFIT);
strcpy(key, v_key);
upstring(key,key);
index = atoi(v_index);
//获得共享文件句柄
hMap=::OpenFileMapping(FILE_MAP_WRITE,FALSE, VoiceFileIndexTableName);
if (hMap == NULL) {
sprintf(msg, "打开共享文件%s出错",VoiceFileIndexTableName);
::MessageBox(NULL, msg, "DLL message", MB_OK);
ReleaseLock(hlock);
return NULL;
}
//获得文件内存地址的指针
p_Map = MapViewOfFile(hMap,FILE_MAP_WRITE ,0,0,0);
//转换成sempahore指针
pSem = (VFIT *)p_Map;
if (strcmp(key, "INDEXNAME")==0) {
p_result = &(pSem[index-1].indexname);
}
if (strcmp(key, "VOCFILE")==0) {
p_result = &(pSem[index-1].vocfile);
}
if (strcmp(key, "IO_OFFSET")==0) {
p_result = &(pSem[index-1].io_offset);
}
if (strcmp(key, "IO_LENGTH")==0) {
p_result = &(pSem[index-1].io_length);
}
if (strcmp(key, "FILEHANDLE")==0) {
p_result = &(pSem[index-1].filehandle);
}
CloseHandle(hMap);
//if (!UnmapViewOfFile(p_Map))
//{ AfxMessageBox("could not unmap view of file"); }
ReleaseLock(hlock);
return p_result; //返回指向确切内存的位置指针
}
/****************************************************************************
*
函数: int CloseVFIT()
说明: 删除语音文件索引表
*
* 目前还不能关闭文件
*
****************************************************************************/
extern "C" _declspec ( dllexport ) int PASCAL CloseVFIT()
{
HANDLE hMap; //内存文件句柄
LPVOID p_Map; //内存文件的指针,可以象数组一样操作
char msg[TXT_LEN];
hMap=::OpenFileMapping(FILE_MAP_WRITE,FALSE,VoiceFileIndexTableName);
if (hMap == NULL) {
sprintf(msg, "打开共享文件%s出错",VoiceFileIndexTableName);
::MessageBox(NULL, msg, "DLL message", MB_OK);
return -1;
}
//获得文件内存地址的指针
p_Map = MapViewOfFile(hMap,FILE_MAP_WRITE ,0,0,0);
//下面两行代码将把内存文件彻底删除
if (!UnmapViewOfFile(p_Map))
{ AfxMessageBox("could not unmap view of file"); }
CloseHandle(hMap);
return 0;
}
/****************************************************************************
函数: int DiskVFIT(char * diskfile, char * s_number)
说明 :将语音文件索引表写成磁盘文件
filename : 内存文件名
diskfile : 信号灯位置(取值 1 .. 30)
s_number : 写入个数
****************************************************************************/
extern "C" _declspec ( dllexport ) int PASCAL DiskVFIT(char * diskfile, char * s_number)
{
HANDLE hMap; //内存文件句柄
LPVOID p_Map; //内存文件的指针,可以象数组一样操作
OFSTRUCT ofstruct;
OFSTRUCT * pof;
HANDLE hdisk;
DWORD bytes,p_bytes;
VFIT * pSem;
char msg[TXT_LEN];
int number,i;
HANDLE hlock; //共享锁
//等待共享文件被释放,然后抢占并琐定
hlock = WaitLock(MUTEX_VFIT);
//写入磁盘的个数
number = atoi(s_number);
if (number<=0) {
ReleaseLock(hlock);
return 0;
}
pof = &(ofstruct);
//获得共享文件句柄
hMap=::OpenFileMapping(FILE_MAP_WRITE,FALSE, VoiceFileIndexTableName);
if (hMap == NULL) {
sprintf(msg, "打开共享文件%s出错",VoiceFileIndexTableName);
::MessageBox(NULL, msg, "DLL message", MB_OK);
ReleaseLock(hlock);
return NULL;
}
//获得文件内存地址的指针
p_Map = MapViewOfFile(hMap,FILE_MAP_WRITE ,0,0,0);
//转换成sempahore指针
pSem = (VFIT *)p_Map;
hdisk = CreateFile(diskfile,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if (hdisk==INVALID_HANDLE_VALUE){
sprintf(msg, "创建磁盘映像文件%s出错",diskfile);
::MessageBox(NULL, msg, "DLL message", MB_OK);
CloseHandle(hMap);
ReleaseLock(hlock);
return -1;
}
for(i=0; i<number; i++)
{
sprintf(msg, "\nVFIT[%d].......\n", i);
bytes = strlen(msg);
if(WriteFile(hdisk, msg, bytes, &p_bytes,NULL)==0) {
//::MessageBox(NULL, "写磁盘映像文件出错", "DLL message", MB_OK);
}
sprintf(msg, ".indexname=[%s]\n", pSem[i].indexname);
bytes = strlen(msg);
if(WriteFile(hdisk, msg, bytes, &p_bytes,NULL)==0) {
//::MessageBox(NULL, "写磁盘映像文件出错", "DLL message", MB_OK);
}
sprintf(msg, ".vocfile=[%s]\n", pSem[i].vocfile);
bytes = strlen(msg);
if(WriteFile(hdisk, msg, bytes, &p_bytes,NULL)==0) {
//::MessageBox(NULL, "写磁盘映像文件出错", "DLL message", MB_OK);
}
sprintf(msg, ".io_offset=[%s]\n", pSem[i].io_offset);
bytes = strlen(msg);
if(WriteFile(hdisk, msg, bytes, &p_bytes,NULL)==0) {
//::MessageBox(NULL, "写磁盘映像文件出错", "DLL message", MB_OK);
}
sprintf(msg, ".io_length=[%s]\n", pSem[i].io_length);
bytes = strlen(msg);
if(WriteFile(hdisk, msg, bytes, &p_bytes,NULL)==0) {
//::MessageBox(NULL, "写磁盘映像文件出错", "DLL message", MB_OK);
}
sprintf(msg, ".io_filehandle=[%s]\n", pSem[i].filehandle);
bytes = strlen(msg);
if(WriteFile(hdisk, msg, bytes, &p_bytes,NULL)==0) {
//::MessageBox(NULL, "写磁盘映像文件出错", "DLL message", MB_OK);
}
}
CloseHandle(hdisk);
CloseHandle(hMap);
ReleaseLock(hlock);
return 0;
}
/**********************************************************************************************
*
*
* 通道语音链表区操作函数
*
*
**********************************************************************************************/
/***************************************************************
*
* 函数 CreateCVCA(char * s_number)
* 说明:在内存中创建CVCA
*
***************************************************************/
extern "C" _declspec ( dllexport ) int PASCAL CreateCVCA(char * s_number)
{
char msg[TXT_LEN];
int number;
HANDLE hMap; //内存文件句柄
//LPVOID p_Map; //内存文件的指针,可以象数组一样操作
number = atoi(s_number);
if (number<=0){
return 0;
}
hMap = CreateFileMapping((HANDLE)-1,NULL,PAGE_READWRITE,0, sizeof(CVCA)*number,ChannelVoiceChainAreaName);
if (hMap != NULL) { //文件创建成功
if(GetLastError() == ERROR_ALREADY_EXISTS) {
//::MessageBox(NULL, "通道语音链表区件已经存在", "信息", MB_OK);
}
else{
//::MessageBox(NULL, "通道语音链表区件创建成功", "信息", MB_OK);
}
//共享资源已经创建,然后创建资源共享琐
CreateShareLock(MUTEX_CVCA);
return 1;
}
else {
sprintf(msg, "创建/打开通道语音链表区%s出错",ChannelVoiceChainAreaName);
::MessageBox(NULL, msg, "信息", MB_OK);
return 0;
}
}
/****************************************************************************
函数: int SetCVCA(char * v_index, char * key, char * v_value)
说明:给初始化文件赋值
index : 信号灯位置(取值 1 .. 30)
key : 项目 (取值 "RecordNum", "ExpNum", "PlayNum")
value : 用于复制的变量
****************************************************************************/
extern "C" _declspec ( dllexport ) int PASCAL SetCVCA(char * v_index, char * skey, char * v_value)
{
CVCA * pSem;
char msg[1024], value[1024];
char key[40];
int index;
HANDLE hMap; //内存文件句柄
LPVOID p_Map; //内存文件的指针,可以象数组一样操作
HANDLE hlock; //共享锁
//等待共享文件被释放,然后抢占并琐定
hlock = WaitLock(MUTEX_CVCA);
strcpy(value, v_value);
index = atoi(v_index);
strcpy(key, skey);
upstring(key,key);
//打开通道语音链表区
hMap=::OpenFileMapping(FILE_MAP_WRITE,FALSE, ChannelVoiceChainAreaName);
if (hMap == NULL) {
sprintf(msg, "打开通道语音链表区%s出错",ChannelVoiceChainAreaName);
::MessageBox(NULL, msg, "DLL message", MB_OK);
ReleaseLock(hlock);
return 0;
}
//获得文件内存地址的指针
p_Map = MapViewOfFile(hMap,FILE_MAP_WRITE ,0,0,0);
if (p_Map == NULL) {
::MessageBox(NULL, msg, "p_Map is null)", MB_OK);
}
pSem = (CVCA *)p_Map;
if (pSem == NULL) {
::MessageBox(NULL, msg, "pSem is null)", MB_OK);
}
if (strcmp(key, "RECORDNUM")==0) {
strcpy(pSem[index-1].RecordNum ,value);
}
if (strcmp(key, "EXPNUM")==0) {
strcpy(pSem[index-1].ExpNum ,value);
}
if (strcmp(key, "PLAYNUM")==0) {
strcpy(pSem[index-1].PlayNum ,value);
}
CloseHandle(hMap);
ReleaseLock(hlock);
return 1;
}
/****************************************************************************
函数: int SetCVCAVocieChain(char * channel, char * chain, char * node, char * key, char * value )
说明: 给通道语音链赋值
channel : 通道位置(取值 1 .. 30)
chain : 链表号( '1' or '2')
node : 链表节点号(‘1’ ~ MaxVoiceChainNode)
key : 项目 (取值 "NodeType", "Content")
value : 值
****************************************************************************/
extern "C" _declspec ( dllexport ) int PASCAL SetCVCAVoiceChain(char * channel, char * chain, char * node, char * skey, char * svalue )
{
CVCA * pSem;
char msg[1024], key[40], value[60];
int iChannel,iChain,iNode;
HANDLE hMap; //内存文件句柄
LPVOID p_Map; //内存文件的指针,可以象数组一样操作
HANDLE hlock; //共享锁
//等待共享文件被释放,然后抢占并琐定
hlock = WaitLock(MUTEX_CVCA);
strcpy(value, svalue);
iChannel = atoi(channel);
strcpy(key, skey);
upstring(key,key);
iChain = atoi(chain)-1;
iNode = atoi(node)-1;
//打开通道语音链表区
hMap=::OpenFileMapping(FILE_MAP_WRITE,FALSE, ChannelVoiceChainAreaName);
if (hMap == NULL) {
sprintf(msg, "SetCVCAVoiceChain():打开通道语音链表区%s出错",ChannelVoiceChainAreaName);
::MessageBox(NULL, msg, "DLL message", MB_OK);
ReleaseLock(hlock);
return 0;
}
//获得文件内存地址的指针
p_Map = MapViewOfFile(hMap,FILE_MAP_WRITE ,0,0,0);
if (p_Map == NULL) {
::MessageBox(NULL, msg, "SetCVCAVoiceChain():p_Map is null)", MB_OK);
}
pSem = (CVCA *)p_Map;
if (pSem == NULL) {
::MessageBox(NULL, msg, "SetCVCAVoiceChain(():pSem is null)", MB_OK);
}
if (strcmp(key, "NODETYPE")==0) {
strcpy(pSem[iChannel-1].VoiceChain[iChain][iNode].NodeType ,value);
}
if (strcmp(key, "CONTENT")==0) {
strcpy(pSem[iChannel-1].VoiceChain[iChain][iNode].Content ,value);
}
CloseHandle(hMap);
ReleaseLock(hlock);
return 1;
}
/****************************************************************************
函数: int ReadCVCA(char * v_index, char * v_key, LPSTR v_value)
说明:给初始化文件赋值
filename : 内存文件名
index : 信号灯位置(取值 1 .. 30)
key : 项目 (取值 "RecordNum", "ExpNum", "PlayNum","io_length", "filehandle")
value : 用于复制的变量
****************************************************************************/
extern "C" _declspec ( dllexport ) LPVOID PASCAL ReadCVCA(char * v_index, char * v_key)
{
HANDLE hMap; //内存文件句柄
LPVOID p_Map; //内存文件的指针,可以象数组一样操作
LPVOID p_result;
CVCA * pSem;
char msg[TXT_LEN], key[20];
int index;
HANDLE hlock; //共享锁
//等待共享文件被释放,然后抢占并琐定
hlock = WaitLock(MUTEX_CVCA);
strcpy(key, v_key);
upstring(key,key);
index = atoi(v_index);
//获得通道语音链表区句柄
hMap=::OpenFileMapping(FILE_MAP_WRITE,FALSE, ChannelVoiceChainAreaName);
if (hMap == NULL) {
sprintf(msg, "ReadCVCA():打开通道语音链表区%s出错",ChannelVoiceChainAreaName);
::MessageBox(NULL, msg, "DLL message", MB_OK);
ReleaseLock(hlock);
return NULL;
}
//获得文件内存地址的指针
p_Map = MapViewOfFile(hMap,FILE_MAP_WRITE ,0,0,0);
if (p_Map == NULL) {
::MessageBox(NULL, msg, "ReadCVCA():p_Map is null)", MB_OK);
}
pSem = (CVCA *)p_Map;
if (pSem == NULL) {
::MessageBox(NULL, msg, "ReadCVCA():pSem is null)", MB_OK);
}
if (strcmp(key, "RECORDNUM")==0) {
p_result = &(pSem[index-1].RecordNum);
}
if (strcmp(key, "EXPNUM")==0) {
p_result = &(pSem[index-1].ExpNum);
}
if (strcmp(key, "PLAYNUM")==0) {
p_result = &(pSem[index-1].PlayNum);
}
if (strcmp(key, "VOICECHAIN1")==0) {
p_result = &(pSem[index-1].VoiceChain[0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -