MYOLE.H
上传用户:zdlsnail
上传日期:2007-01-06
资源大小:16k
文件大小:9k
- //-------------------------
- unsigned char readBuffer[100000],selectBuffer[100000],progBuffer[100000];
- BOOL InitCOM()
- {
- HRESULT hErr;
- DWORD coVersion=CoBuildVersion();
- if( HIWORD(coVersion)!=rmm||LOWORD(coVersion)<rup )
- {
- printf("bad version of COMn");
- return FALSE ;
- }
- hErr=CoInitialize(NULL);
- if(FAILED(GetScode(hErr)))
- { printf("Failed to initialize OLE!n");
- return FALSE ; }
- return TRUE ;
- }
- //-------------------------
- void DeinitCOM()
- {
- CoUninitialize();}
- //-------------------------
- void readOleFile( char * mfilename,
- char * mstreamname,
- char * buffer,
- unsigned long *length)
- {
- HRESULT hErr ;
- LPSTORAGE pStg ;
- LPSTREAM pStm ;
- STATSTG * pStat;
- wchar_t wfilename[120];
- wchar_t wstreamname[64];
- int iMessageSize=96,k,j;
- if( !InitCOM()) return;
- while((SetMessageQueue(iMessageSize)==0)&&(iMessageSize>0)){
- iMessageSize-=8;}
-
- j=strlen(mfilename);
- k=mbstowcs(wfilename,mfilename,j+1);
- j=strlen(mstreamname);
- k=mbstowcs(wstreamname,mstreamname,j+1);
-
- hErr=StgOpenStorage(
- wfilename,
- NULL,
- STGM_READ|STGM_TRANSACTED,
- NULL,
- 0,
- & pStg);
- if(FAILED(hErr)) { DeinitCOM();length=0;return;}
- hErr=pStg->OpenStream( wstreamname,
- 0,
- STGM_READ|STGM_DIRECT|STGM_SHARE_EXCLUSIVE,
- 0,
- &pStm );
- if(FAILED(hErr)) {
- pStg->Release(); DeinitCOM();length=0;return;}
- pStm->Stat(pStat,2);
- pStm->Read(buffer,0x7fffffff,length);
- pStm->Release();
- pStg->Release();
- DeinitCOM();return;}
- //----------------------------------
- short getConnectionID()
- {
- char far filename[125];
- char far *ptr,*tmpptr;
- short i;
- char far id_section[]="@_ID_section";
- strcpy(filename,rootDir);
- strcat(filename,author);
- //read
- i=0;tmpptr=ptr;
- while(TRUE) {
- tmpptr=strstr(ptr,"t");
- if(tmpptr==NULL) return(i);
- *tmpptr=' ';
- ConIDStru[i].ID=atoi(ptr);
- ptr=tmpptr+1;
- tmpptr=strstr(ptr,"t");
- if(tmpptr==NULL) return(i);
- ptr=tmpptr+1;
- tmpptr=strstr(ptr,"r");
- if(tmpptr!=NULL) *tmpptr=' ';
- strcpy(ConIDStru[i].connString,ptr);
- i++;
- if(tmpptr==NULL) return(i);
- if(i<MAXCONNECTID) ptr=tmpptr+2;
- else return(i);}}
- //---------------------------------
- void makeConnectString(UCHAR FAR *connectstring,short ID)
- {
- short i;
- i=0;
- while(i<connectCount) {
- if(ID==ConIDStru[i].ID) {
- strcpy(connectstring,ConIDStru[i].connString);
- return;}
- else i++;}
- connectCount=getConnectionID();
- i=0;
- while(i<connectCount) {
- if(ID==ConIDStru[i].ID) {
- strcpy(connectstring,ConIDStru[i].connString);
- return;}
- else i++;}
- *connectstring=' ';}
- //---------------------------------
- short getUserInfo()
- {
- char far filename[125];
- char far *ptr,*tmpptr;
- short i;
- char far id_section[]="@_user_section";
- long len;
- strcpy(filename,rootDir);
- strcat(filename,author);
- readOleFile(filename,id_section,readBuffer,&len);
- readBuffer[len]=' ';
- ptr=&readBuffer[0];
- i=0;tmpptr=ptr;
- while(TRUE) {
- tmpptr=strstr(ptr,"t");
- if(tmpptr==NULL) return(i);
- *tmpptr=' ';
- strcpy(userInfoStru[i].userName,ptr);
- ptr=tmpptr+1;
- tmpptr=strstr(ptr,"t");
- if(tmpptr==NULL) return(i);
- *tmpptr=' ';
- strcpy(userInfoStru[i].passWord,ptr);
- ptr=tmpptr+1;
- tmpptr=strstr(ptr,"t");
- if(tmpptr==NULL) return(i);
- *tmpptr=' ';
- strcpy(userInfoStru[i].winName,ptr);
- ptr=tmpptr+1;
- tmpptr=strstr(ptr,"r");
- if(tmpptr!=NULL) *tmpptr=' ';
- strcpy(userInfoStru[i].pathName,ptr);
- i++;
- if(tmpptr==NULL) return(i);
- if(i<MAXUSER) ptr=tmpptr+2;
- else return(i);}}
- //---------------------------------------------------
- BOOL UserPass(UCHAR FAR * winName,UCHAR FAR *pathName,
- UCHAR FAR *userName,UCHAR FAR *passWord)
- {
- long i;
- i=0;
- while(i<userCount) {
- if((stricmp(userName,userInfoStru[i].userName)==0)&&
- (stricmp(passWord,userInfoStru[i].passWord)==0)) {
- strcpy(winName,userInfoStru[i].winName);
- strcpy(pathName,userInfoStru[i].pathName);
- return(TRUE);}
- else i++;}
- userCount=getUserInfo();
- i=0;
- while(i<userCount) {
- if((stricmp(userName,userInfoStru[i].userName)==0)&&
- (stricmp(passWord,userInfoStru[i].passWord)==0)) {
- strcpy(winName,userInfoStru[i].winName);
- strcpy(pathName,userInfoStru[i].pathName);
- return(TRUE);}
- else i++;}
- return(FALSE);}
- //-----------------------------------------
- BOOL readWinTitle(UCHAR FAR *dwLib,UCHAR FAR *dwName,UCHAR FAR *readwin)
- {
- long i,readlong;
- unsigned char *ptr;
- unsigned char pathname[80];
- strcpy(pathname,rootDir);
- strcat(pathname,"DINDOW.SAV");
- readOleFile(pathname,"window",readBuffer,&readlong);
- i=0;
- ptr=&readBuffer[0];
- while(i<readlong) {
- if(memcmp(ptr,dwName,14)==0) {
- memcpy(readwin,ptr,108);
- readwin[108]=' ';return(TRUE);}
- ptr=ptr+108;i=i+108;}
- return(FALSE);}
- //-----------------------------------------
- //transfer string to a lib structure item
- long setWinLib(UCHAR FAR *buffer,short k,long pos)
- {
- short len,index;
- unsigned char strlen[6],dwname[50],*ptr,pathname[80];
- long length,addlen;
- index=0;
- memcpy(strlen,buffer,5);
- addlen=0;
- strlen[5]=' ';
- len=atoi(strlen);
- index=index+5;
- memcpy(&connectStru[k].returnstring[pos],&buffer[index],len);
- index=index+len;
- pos=pos+len;
- addlen=addlen+len;
- connectStru[k].returnstring[pos]=',';
- pos++;addlen++;
- memcpy(strlen,&buffer[index],5);
- strlen[5]=' ';
- len=atoi(strlen);
- index=index+5+len;
- memcpy(strlen,&buffer[index],5);
- strlen[5]=' ';
- len=atoi(strlen);
- index=index+5;
- memcpy(&connectStru[k].returnstring[pos],&buffer[index],len);
- memcpy(dwname,&buffer[index],len);
- dwname[len]=' ';
- index=index+len;
- pos=pos+len;addlen=addlen+len;
- connectStru[k].returnstring[pos]=',';
- pos++;addlen++;
- strcpy(pathname,rootDir);
- strcat(pathname,"DATAWIN.SAV");
- readOleFile(pathname,dwname,&connectStru[k].returnstring[pos],&length);
- pos=pos+length;addlen=addlen+length;
- connectStru[k].returnstring[pos]=',';
- pos++;addlen++;
- ptr=strstr(selectBuffer,dwname);
- if(ptr==NULL) {connectStru[k].returnstring[pos]=',';pos++;addlen++;}
- else {
- ptr=ptr+50;
- memcpy(&connectStru[k].returnstring[pos],ptr,14);
- pos=pos+14;addlen=addlen+14;
- connectStru[k].returnstring[pos]=',';
- pos++;addlen++;}
- ptr=strstr(progBuffer,dwname);
- if(ptr==NULL) {connectStru[k].returnstring[pos]=',';pos++;addlen++;}
- else {
- ptr=ptr+50;
- memcpy(&connectStru[k].returnstring[pos],ptr,14);
- pos=pos+14;addlen=addlen+14;
- connectStru[k].returnstring[pos]=',';
- pos++;addlen++;}
- return(addlen);}
- //-----------------------------------------
- void readWinInfo(UCHAR FAR *dwLib,UCHAR FAR *dwName,
- UCHAR FAR *dateString,short wwmark,short k)
- {
- UCHAR FAR readwin[120],pathname[80];
- char ch[2],stringlen[8],*ptr;
- long returnPos,j,index,maxbuffer,len,pos;
- short num1,i;
- if(readWinTitle(dwLib,dwName,readwin)==FALSE) {
- WriteHtml(connectStru[k].pECB,"ERROR006");
- return;}
- if(wwmark==0) {
- WriteHtml(connectStru[k].pECB,"000000WB");
- strcpy(connectStru[k].returnstring,readwin);
- returnPos=108;}
- else {
- if(memcmp(&readwin[64],dateString,14)==0) {
- WriteHtml(connectStru[k].pECB,"000000WO");
- returnPos=0;}
- else {
- WriteHtml(connectStru[k].pECB,"000000WR");
- strcpy(connectStru[k].returnstring,readwin);
- returnPos=108;wwmark=2;}}
- readwin[14]=' ';
- strcpy(pathname,rootDir);
- strcat(pathname,"WINDOW.SAV");
- readOleFile(pathname,readwin,readBuffer,&maxbuffer);
- if(wwmark==2) {
- ltoa(maxbuffer,stringlen,10);
- strcpy(&connectStru[k].returnstring[returnPos],stringlen);
- returnPos=returnPos+strlen(&connectStru[k].returnstring[returnPos]);
- connectStru[k].returnstring[returnPos]='t';
- returnPos++;}
- index=0;
- num1=0;pos=returnPos;returnPos=returnPos+5;
- strcpy(pathname,rootDir);
- strcat(pathname,"DSELECT.SAV");
- readOleFile(pathname,"WINDOW",selectBuffer,&len);
- selectBuffer[len]=' ';
- strcpy(pathname,rootDir);
- strcat(pathname,"DPROGRAM.SAV");
- readOleFile(pathname,"WINDOW",progBuffer,&len);
- progBuffer[len]=' ';
- while(index<maxbuffer) {
- memcpy(ch,readBuffer,1);
- memcpy(stringlen,&readBuffer[1],5);
- stringlen[5]=' ';
- len=atol(stringlen);
- if(stricmp(ch,"L")==0) {
- returnPos=returnPos +
- setWinLib(&readBuffer[index+6],k,returnPos);
- num1++;}
- index = index + 6 + len;}
- itoa(num1,stringlen,10);
- ptr=&connectStru[k].returnstring[pos];
- j=5 - (short)(strlen(stringlen));
- for(i=0;i<j;i++) {*ptr='0';ptr++;}
- memcpy(ptr,stringlen,strlen(stringlen));
- connectStru[k].returnstring[returnPos]=' ';
- sendsqlresult(k);}