⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functopt.cpp

📁 中国联通短信网络协议SGIP,可直接与联通短信网关相连
💻 CPP
字号:
#include "stdafx.h"
#include <string.h>
#include <share.h>

void stocpy(unsigned long * ltemp,char * btemp)
{
  BYTE temp[5];

  memset(temp,0,sizeof(temp));
  temp[0]=btemp[3];
  temp[1]=btemp[2];
  temp[2]=btemp[1];
  temp[3]=btemp[0];
  memcpy(ltemp,temp,sizeof(unsigned long));
}

void ltocpy(char * btemp,unsigned long ltemp)
{
  BYTE temp[10];

  memset(temp,0,sizeof(temp));
  memcpy(temp,&ltemp,sizeof(ltemp));
  btemp[0]=temp[3];
  btemp[1]=temp[2];
  btemp[2]=temp[1];
  btemp[3]=temp[0];
}

int AnsiToUnicode(PSTR pMultiByteStr,char *unicode,int flag=0)
{
	WCHAR pWideCharStr[4096];
	int nLenOfWideCharStr,length,i;
	char temp[8192];
	
	memset(pWideCharStr,0,sizeof(pWideCharStr));
    memset(temp,0,sizeof(temp));

	nLenOfWideCharStr=MultiByteToWideChar(936,0,pMultiByteStr,-1,NULL,0);

	MultiByteToWideChar(936,0,pMultiByteStr,-1,pWideCharStr,nLenOfWideCharStr);

    memcpy(temp,pWideCharStr,sizeof(pWideCharStr));

	length=wcslen(pWideCharStr);
    
	if(flag==0)
	{
		memcpy(unicode,temp,length*2);
	}
	else
	{// network order
         for(i=0;i<length;i++)
		 {
			unicode[2*i]=temp[2*i+1];
			unicode[2*i+1]=temp[2*i];
		 }
	}
	return length;
}
int UnicodeToAnsi(char *unicode,PSTR pMultiByteStr,int flag=1)
{
	//WCHAR pWideCharStr[4096];.
	int nLenOfMultiByteCharStr,length,i;
	char temp[8192];
	
///	memset(pWideCharStr,0,sizeof(pWideCharStr));
    memset(temp,0,sizeof(temp));

	
    ///memcpy(temp,pWideCharStr,sizeof(pWideCharStr));

	length=wcslen((WCHAR *)unicode);
    
	if(!flag)
	{
		memcpy(temp,unicode,length*2);
	}
	else
	{// network order
         for(i=0;i<length;i++)
		 {
			temp[2*i]=unicode[2*i+1];
			temp[2*i+1]=unicode[2*i];
		 }
	}
	//return length;
	nLenOfMultiByteCharStr=WideCharToMultiByte(936,0,(WCHAR *)temp,-1,NULL,0,NULL,NULL);

	i=WideCharToMultiByte(936,0,(WCHAR *)temp,-1,pMultiByteStr,nLenOfMultiByteCharStr,NULL,NULL);
	return i;

}

void AddParityChar(BYTE *szBuffer)
{
  int i,len;
  long count=0;

  len=strlen((char *)szBuffer);
  for (i=0;i<len;i++)
    count+=szBuffer[i];
  szBuffer[len+1]='\0';
  szBuffer[len]=count%16L+'0';
}

int CheckParity(BYTE  *buff)
{
  int i,len;
  long count;
  char ParityChar;

  len=strlen((char *)buff);

  if (len<4)
    return 1;

  count=0L;
  ParityChar=buff[len-1];
  for (i=0;i<(len-1);i++)
    count+=buff[i];
  count%=16;
  if ((count+'0')==ParityChar)
    return 0;
  return 1;
}

void writelog()
{
	static			tOldTime=time(NULL);
	time_t			tCurTime;
	double			lDiffTime;
	char m_szActiveFlag[30]="hgsmsend.Log",ss[50];
	FILE *file;

	time(&tCurTime);
	lDiffTime = abs(difftime(tCurTime , tOldTime)) - 30;
	if (lDiffTime > 0 ){
		if ((file=_fsopen(m_szActiveFlag,"w+",SH_DENYNO))==NULL) {
//			sprintf(ss,"%s  can't be created. ",m_szActiveFlag);
//			AfxMessageBox(ss);
//			printf("%s  can't be created. \n",m_szActiveFlag);
		}
		fclose(file);
		tOldTime = tCurTime;
	}
}
/*
void writelog()
{
	static			tOldTime=time(NULL);
	time_t			tCurTime;
	double			lDiffTime;
	char m_szActiveFlag[30]="hgsmsend.Log",ss[50];
	CString         strTrace ;

	time(&tCurTime);
	lDiffTime = abs(difftime(tCurTime , tOldTime)) - 30;
	if (lDiffTime > 0 ){
		TRY
		{
		   CFile f( m_szActiveFlag , CFile::modeCreate | CFile::modeWrite );  //m_szActiveFlag 是活动日志文件名
		   f.Close();
		} 
		CATCH( CFileException, e )
		{
			strTrace.Format("%s  can't be created. ",m_szActiveFlag ) ;
//		        LogMsg(strTrace ); //显示strTrace的内容
		}
		END_CATCH
		tOldTime = tCurTime;
	}
}
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -