#include "stdafx.h"
#include <string>
using namespace std;
extern "c" {
retcode __declspec(dllexport) xp_part_init(srv_proc *srvproc);
retcode __declspec(dllexport) xp_part_process(srv_proc *srvproc);
retcode __declspec(dllexport) xp_part_finalize(srv_proc *srvproc);
}
#define xp_noerror 0
#define xp_error 1
hinstance hinst = null;
int nref = 0;
void printerror (srv_proc *psrvproc, char* szerrormsg);
ulong __getxpversion(){ return ods_version;}
srvretcode xp_part_init(srv_proc* psrvproc){
typedef bool (*func)();
if(nref == 0){
hinst = ::loadlibrary("part.dll");
if(hinst == null){
printerror(psrvproc,"不能加载part.dll");
return xp_error;
}
func thefunc = (func)::getprocaddress(hinst,"init");
if(!thefunc()){
::freelibrary(hinst);
printerror(psrvproc,"不能获得分类号与专辑的对应表");
return xp_error;
}
}
++ nref;
return (xp_noerror);
}
srvretcode xp_part_process(srv_proc* psrvproc){
typedef bool (*func)(char*);
if(nref == 0){
printerror(psrvproc,"函数尚未初始化,请首先调用xp_part_init");
return xp_error;
}
func thefunc = (func)::getprocaddress(hinst,"get");
byte btype;
ulong cbmaxlen,cbactuallen;
bool fnull;
char szinput[256] = {0};
if (srv_paraminfo(psrvproc, 1, &btype, (ulong*)&cbmaxlen, (ulong*)&cbactuallen, (byte*)szinput, &fnull) == fail){
printerror(psrvproc,"srv_paraminfo 返回 fail");
return xp_error;
}
szinput[cbactuallen] = 0;
string strinput = szinput;
string stroutput = ";";
int cur,old = 0;
while(string::npos != (cur = strinput.find(’;’,old)) ){
strncpy(szinput,strinput.c_str() + old,cur - old);
szinput[cur - old] = 0;
old = cur + 1;
thefunc(szinput);
if(string::npos ==stroutput.find((string)";" + szinput))
stroutput += szinput;
}
strcpy(szinput,stroutput.c_str());
if (fail == srv_paramsetoutput(psrvproc, 1, (byte*)(szinput + 1), strlen(szinput) - 1,false)){
printerror (psrvproc, "srv_paramsetoutput 调用失败");
return xp_error;
}
srv_senddone(psrvproc, (srv_done_count | srv_done_more), 0, 0);
return xp_noerror;
}
srvretcode xp_part_finalize(srv_proc* psrvproc){
typedef void (*func)();
if(nref == 0)
return xp_noerror;
func thefunc = (func)::getprocaddress(hinst,"fin");
if((--nref) == 0){
thefunc();
::freelibrary(hinst);
hinst = null;
}
return (xp_noerror);
}
新闻热点
疑难解答