MYOLE.H
上传用户:zdlsnail
上传日期:2007-01-06
资源大小:16k
文件大小:9k
源码类别:

压缩解压

开发平台:

Visual C++

  1. //-------------------------
  2. unsigned char readBuffer[100000],selectBuffer[100000],progBuffer[100000];
  3. BOOL InitCOM()
  4.  {
  5.     HRESULT hErr;
  6. DWORD coVersion=CoBuildVersion();
  7.    if( HIWORD(coVersion)!=rmm||LOWORD(coVersion)<rup )
  8.    {
  9.       printf("bad version of COMn");
  10.       return FALSE ; 
  11.         }
  12.    hErr=CoInitialize(NULL);
  13.    if(FAILED(GetScode(hErr))) 
  14.      { printf("Failed to initialize OLE!n");
  15.        return  FALSE ; }
  16.  return TRUE ;
  17. }
  18. //-------------------------
  19. void DeinitCOM()
  20. {
  21.    CoUninitialize();}
  22. //-------------------------
  23. void readOleFile( char * mfilename,
  24.   char * mstreamname,
  25.   char * buffer,
  26.   unsigned long *length)
  27. {
  28.   HRESULT    hErr ;
  29.   LPSTORAGE  pStg ;
  30.   LPSTREAM   pStm ;
  31.   STATSTG  * pStat;
  32.   wchar_t wfilename[120];
  33.   wchar_t wstreamname[64];
  34.   int iMessageSize=96,k,j;
  35.   if( !InitCOM()) return;
  36.   while((SetMessageQueue(iMessageSize)==0)&&(iMessageSize>0)){
  37.    iMessageSize-=8;}
  38.  
  39.   j=strlen(mfilename);
  40.   k=mbstowcs(wfilename,mfilename,j+1);
  41.   j=strlen(mstreamname);
  42.   k=mbstowcs(wstreamname,mstreamname,j+1);
  43.   
  44.   hErr=StgOpenStorage(
  45.           wfilename,
  46.   NULL,
  47.               STGM_READ|STGM_TRANSACTED,
  48.   NULL,
  49.   0,
  50.   & pStg);
  51.  if(FAILED(hErr)) { DeinitCOM();length=0;return;} 
  52.  hErr=pStg->OpenStream( wstreamname,
  53.                     0,
  54. STGM_READ|STGM_DIRECT|STGM_SHARE_EXCLUSIVE,
  55.                         0,
  56. &pStm );
  57.  if(FAILED(hErr)) {
  58.    pStg->Release(); DeinitCOM();length=0;return;}
  59.  pStm->Stat(pStat,2);
  60.  pStm->Read(buffer,0x7fffffff,length); 
  61.  pStm->Release();
  62.  pStg->Release();
  63.  DeinitCOM();return;}
  64. //----------------------------------
  65. short getConnectionID() 
  66.   {
  67. char far filename[125];
  68. char far *ptr,*tmpptr;
  69. short i;
  70.     char far id_section[]="@_ID_section";
  71. strcpy(filename,rootDir);
  72. strcat(filename,author);
  73. //read
  74. i=0;tmpptr=ptr;
  75. while(TRUE) {
  76.   tmpptr=strstr(ptr,"t");
  77.   if(tmpptr==NULL) return(i);
  78.   *tmpptr='';
  79.       ConIDStru[i].ID=atoi(ptr);
  80.   ptr=tmpptr+1;
  81.   tmpptr=strstr(ptr,"t");
  82.   if(tmpptr==NULL) return(i);
  83.   ptr=tmpptr+1;
  84.   tmpptr=strstr(ptr,"r");
  85.   if(tmpptr!=NULL) *tmpptr='';
  86.       strcpy(ConIDStru[i].connString,ptr);
  87.   i++;
  88.   if(tmpptr==NULL) return(i);
  89.   if(i<MAXCONNECTID) ptr=tmpptr+2;
  90.       else return(i);}}
  91. //---------------------------------
  92.       void makeConnectString(UCHAR FAR *connectstring,short ID) 
  93.     {
  94.    short i;
  95.    i=0;
  96.    while(i<connectCount) {
  97.  if(ID==ConIDStru[i].ID) {
  98.    strcpy(connectstring,ConIDStru[i].connString);
  99.    return;}
  100.      else i++;} 
  101.            connectCount=getConnectionID(); 
  102.            i=0;
  103.    while(i<connectCount) {
  104.      if(ID==ConIDStru[i].ID) {
  105.                strcpy(connectstring,ConIDStru[i].connString);
  106.        return;}
  107.  else i++;}
  108.    *connectstring='';}
  109. //---------------------------------
  110. short getUserInfo() 
  111.   {
  112. char far filename[125];
  113. char far *ptr,*tmpptr;
  114. short i;
  115.     char far id_section[]="@_user_section";
  116. long len;
  117. strcpy(filename,rootDir);
  118. strcat(filename,author);
  119. readOleFile(filename,id_section,readBuffer,&len);
  120. readBuffer[len]='';
  121. ptr=&readBuffer[0];
  122. i=0;tmpptr=ptr;
  123. while(TRUE) {
  124.   tmpptr=strstr(ptr,"t");
  125.   if(tmpptr==NULL) return(i);
  126.   *tmpptr='';
  127.       strcpy(userInfoStru[i].userName,ptr);
  128.   ptr=tmpptr+1;
  129.   tmpptr=strstr(ptr,"t");
  130.   if(tmpptr==NULL) return(i);
  131.   *tmpptr='';
  132.       strcpy(userInfoStru[i].passWord,ptr);
  133.   ptr=tmpptr+1;
  134.   tmpptr=strstr(ptr,"t");
  135.   if(tmpptr==NULL) return(i);
  136.   *tmpptr='';
  137.       strcpy(userInfoStru[i].winName,ptr);
  138.   ptr=tmpptr+1;
  139.   tmpptr=strstr(ptr,"r");
  140.   if(tmpptr!=NULL) *tmpptr='';
  141.       strcpy(userInfoStru[i].pathName,ptr);
  142.   i++;
  143.   if(tmpptr==NULL) return(i);
  144.   if(i<MAXUSER) ptr=tmpptr+2;
  145.       else return(i);}}
  146. //---------------------------------------------------
  147. BOOL UserPass(UCHAR FAR * winName,UCHAR FAR *pathName,
  148.   UCHAR FAR *userName,UCHAR FAR *passWord) 
  149.   {
  150.     long i;
  151.     i=0;
  152.     while(i<userCount) {
  153.       if((stricmp(userName,userInfoStru[i].userName)==0)&&
  154.     (stricmp(passWord,userInfoStru[i].passWord)==0)) {
  155.           strcpy(winName,userInfoStru[i].winName);
  156.           strcpy(pathName,userInfoStru[i].pathName);
  157.   return(TRUE);}
  158.       else i++;} 
  159.     userCount=getUserInfo(); 
  160.     i=0;
  161.     while(i<userCount) {
  162.       if((stricmp(userName,userInfoStru[i].userName)==0)&&
  163.     (stricmp(passWord,userInfoStru[i].passWord)==0)) {
  164.           strcpy(winName,userInfoStru[i].winName);
  165.           strcpy(pathName,userInfoStru[i].pathName);
  166.   return(TRUE);}
  167.       else i++;} 
  168.     return(FALSE);}
  169. //-----------------------------------------
  170. BOOL readWinTitle(UCHAR FAR *dwLib,UCHAR FAR *dwName,UCHAR FAR *readwin)
  171.   {
  172. long i,readlong;
  173. unsigned char *ptr;
  174. unsigned char pathname[80];
  175. strcpy(pathname,rootDir);
  176. strcat(pathname,"DINDOW.SAV");
  177. readOleFile(pathname,"window",readBuffer,&readlong);
  178.     i=0;
  179. ptr=&readBuffer[0];
  180. while(i<readlong) {
  181.   if(memcmp(ptr,dwName,14)==0) {
  182. memcpy(readwin,ptr,108);
  183. readwin[108]='';return(TRUE);}
  184.   ptr=ptr+108;i=i+108;}
  185. return(FALSE);}
  186. //-----------------------------------------
  187. //transfer string to a lib structure item
  188. long setWinLib(UCHAR FAR *buffer,short k,long pos)
  189.   {
  190.     short len,index;
  191. unsigned char strlen[6],dwname[50],*ptr,pathname[80];
  192. long length,addlen;
  193.     index=0;
  194. memcpy(strlen,buffer,5);
  195. addlen=0;
  196. strlen[5]='';
  197.     len=atoi(strlen);
  198.     index=index+5;
  199.     memcpy(&connectStru[k].returnstring[pos],&buffer[index],len);
  200. index=index+len;
  201. pos=pos+len;
  202. addlen=addlen+len;
  203. connectStru[k].returnstring[pos]=',';
  204. pos++;addlen++;
  205. memcpy(strlen,&buffer[index],5);
  206. strlen[5]='';
  207.     len=atoi(strlen);
  208.     index=index+5+len;
  209. memcpy(strlen,&buffer[index],5);
  210. strlen[5]='';
  211.     len=atoi(strlen);
  212.     index=index+5;
  213.     memcpy(&connectStru[k].returnstring[pos],&buffer[index],len);
  214.     memcpy(dwname,&buffer[index],len);
  215. dwname[len]='';
  216. index=index+len;
  217. pos=pos+len;addlen=addlen+len;
  218. connectStru[k].returnstring[pos]=',';
  219. pos++;addlen++;
  220.     strcpy(pathname,rootDir);
  221. strcat(pathname,"DATAWIN.SAV");
  222. readOleFile(pathname,dwname,&connectStru[k].returnstring[pos],&length);
  223. pos=pos+length;addlen=addlen+length;
  224. connectStru[k].returnstring[pos]=',';
  225. pos++;addlen++;
  226. ptr=strstr(selectBuffer,dwname);
  227. if(ptr==NULL) {connectStru[k].returnstring[pos]=',';pos++;addlen++;}
  228. else {
  229.   ptr=ptr+50;
  230.   memcpy(&connectStru[k].returnstring[pos],ptr,14);
  231.       pos=pos+14;addlen=addlen+14;
  232.       connectStru[k].returnstring[pos]=',';
  233.   pos++;addlen++;}
  234. ptr=strstr(progBuffer,dwname);
  235. if(ptr==NULL) {connectStru[k].returnstring[pos]=',';pos++;addlen++;}
  236. else {
  237.   ptr=ptr+50;
  238.   memcpy(&connectStru[k].returnstring[pos],ptr,14);
  239.       pos=pos+14;addlen=addlen+14;
  240.       connectStru[k].returnstring[pos]=',';
  241.   pos++;addlen++;}
  242.     return(addlen);}
  243. //-----------------------------------------
  244. void readWinInfo(UCHAR FAR *dwLib,UCHAR FAR *dwName,
  245.    UCHAR FAR *dateString,short wwmark,short k) 
  246.   {
  247. UCHAR FAR readwin[120],pathname[80]; 
  248. char ch[2],stringlen[8],*ptr;
  249. long returnPos,j,index,maxbuffer,len,pos;
  250. short num1,i;
  251. if(readWinTitle(dwLib,dwName,readwin)==FALSE) {
  252.       WriteHtml(connectStru[k].pECB,"ERROR006");
  253.   return;}
  254.     if(wwmark==0) {
  255.       WriteHtml(connectStru[k].pECB,"000000WB");
  256.       strcpy(connectStru[k].returnstring,readwin);
  257.   returnPos=108;}
  258. else {
  259.   if(memcmp(&readwin[64],dateString,14)==0) {
  260.         WriteHtml(connectStru[k].pECB,"000000WO");
  261.     returnPos=0;}
  262.   else {
  263.         WriteHtml(connectStru[k].pECB,"000000WR");
  264.       strcpy(connectStru[k].returnstring,readwin);
  265. returnPos=108;wwmark=2;}}
  266. readwin[14]='';
  267.     strcpy(pathname,rootDir);
  268.     strcat(pathname,"WINDOW.SAV");
  269. readOleFile(pathname,readwin,readBuffer,&maxbuffer);
  270. if(wwmark==2) {
  271.   ltoa(maxbuffer,stringlen,10);
  272.   strcpy(&connectStru[k].returnstring[returnPos],stringlen);
  273.   returnPos=returnPos+strlen(&connectStru[k].returnstring[returnPos]);
  274.   connectStru[k].returnstring[returnPos]='t';
  275.   returnPos++;}
  276.     index=0;
  277. num1=0;pos=returnPos;returnPos=returnPos+5;
  278. strcpy(pathname,rootDir);
  279. strcat(pathname,"DSELECT.SAV");
  280. readOleFile(pathname,"WINDOW",selectBuffer,&len);
  281. selectBuffer[len]='';
  282. strcpy(pathname,rootDir);
  283. strcat(pathname,"DPROGRAM.SAV");
  284.     readOleFile(pathname,"WINDOW",progBuffer,&len);
  285. progBuffer[len]='';
  286.     while(index<maxbuffer) {
  287.   memcpy(ch,readBuffer,1);
  288.   memcpy(stringlen,&readBuffer[1],5);
  289.   stringlen[5]='';
  290.   len=atol(stringlen);
  291.   if(stricmp(ch,"L")==0) {
  292.         returnPos=returnPos +
  293.   setWinLib(&readBuffer[index+6],k,returnPos);
  294.     num1++;}
  295.   index = index + 6 + len;}
  296.   itoa(num1,stringlen,10);
  297.       ptr=&connectStru[k].returnstring[pos];
  298.       j=5 - (short)(strlen(stringlen));
  299.       for(i=0;i<j;i++) {*ptr='0';ptr++;}
  300.       memcpy(ptr,stringlen,strlen(stringlen));
  301.   connectStru[k].returnstring[returnPos]='';
  302.       sendsqlresult(k);}