?? command.cpp
字號:
static char* inf_empty="空";
CString infoempty("上一級數據");
if(run_info)
delete[] run_info;
run_info=new char[5];
for(int i=0;i<5;i++)
run_info[i]=inf_empty[i];
(data_in+1)->mset_data(infoempty.GetBuffer(4),infoempty.GetLength()+4,type_mw,NULL,NULL,data_in->the_length,data_in->pdata.mw);
//*(data_in+1)=*data_in;
}
int z=0;
return result;
}
_declspec(dllexport) void operator <<(CArchive& ar,command& it)
{
ar<<int(it.cmd_type);
if(!(it.cmd_type==function))
{
ar<<it.clsid.Data1;
ar<<it.clsid.Data2;
ar<<it.clsid.Data3;
for(int i=0;i<8;i++)
ar<<it.clsid.Data4[i];
ar<<it.iid.Data1;
ar<<it.iid.Data2;
ar<<it.iid.Data3;
for(i=0;i<8;i++)
ar<<it.iid.Data4[i];
ar<<it.libid.Data1;
ar<<it.libid.Data2;
ar<<it.libid.Data3;
for(i=0;i<8;i++)
ar<<it.libid.Data4[i];
}
ar<<it.cmd_id;
ar<<int(it.cmd_lan);
ar<<int(it.level);
ar<<it.info_length;
for(int i=0;i<it.info_length;i++)
ar<<it.cmd_info[i];
ar<<it.where_length;
for(i=0;i<it.where_length;i++)
ar<<it.cmd_where[i];
ar<<it.name_length;
for(i=0;i<it.name_length;i++)
ar<<it.cmd_name[i];
ar<<it.conector_cnt;
for(i=0;i<it.conector_cnt;i++)
ar<<it.conector[i];
}
_declspec(dllexport) void operator >>(CArchive& ar,command& it)
{int bag;
ar>>bag;
it.cmd_type=(conect_type)bag;
if(!(it.cmd_type==function))
{
ar>>it.clsid.Data1;
ar>>it.clsid.Data2;
ar>>it.clsid.Data3;
for(unsigned int i=0;i<8;i++)
ar>>it.clsid.Data4[i];
ar>>it.iid.Data1;
ar>>it.iid.Data2;
ar>>it.iid.Data3;
for(i=0;i<8;i++)
ar>>it.iid.Data4[i];
ar>>it.libid.Data1;
ar>>it.libid.Data2;
ar>>it.libid.Data3;
for(i=0;i<8;i++)
ar>>it.libid.Data4[i];
}
ar>>it.cmd_id;
ar>>bag;
it.cmd_lan=(language)bag;
ar>>bag;
it.level=(grade)bag;;
ar>>it.info_length;
it.cmd_info=new char[it.info_length];
for(unsigned int i=0;i<it.info_length;i++)
ar>>it.cmd_info[i];
ar>>it.where_length;
it.cmd_where=new char[it.where_length];
for(i=0;i<it.where_length;i++)
ar>>it.cmd_where[i];
ar>>it.name_length;
it.cmd_name=new char[it.name_length];
for(i=0;i<it.name_length;i++)
ar>>it.cmd_name[i];
ar>>it.conector_cnt;
for(i=0;i<it.conector_cnt;i++)
ar>>it.conector[i];
if(it.level<special)
it.hdll=::LoadLibrary(it.cmd_where);
}
void command::Serialize(CArchive& ar)
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
CObject::Serialize(ar);
if(ar.IsStoring())
ar<<*this;
else
ar>>*this;
}
void tagconector::Serialize(CArchive &ar)
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
if(ar.IsStoring())
ar<<*this;
else
ar>>*this;
}
void command::operator =(command& op)
{
this->clsid=op.clsid;
this->cmd_id=op.cmd_id;
this->info_length=op.info_length;
this->cmd_info=new char[this->info_length+1];
for(unsigned int i=0;i<this->info_length;i++)
this->cmd_info[i]=op.cmd_info[i];
this->cmd_info[info_length]='\0';
this->cmd_lan=op.cmd_lan;
this->cmd_type=op.cmd_type;
this->conector_cnt=op.conector_cnt;
for(i=0;i<this->conector_cnt;i++)
{this->conector[i].description_length=op.conector[i].description_length;
this->conector[i].description=new char[this->conector[i].description_length+1];
for(unsigned int j=0;j<this->conector[i].description_length;j++)
this->conector[i].description[j]=op.conector[i].description[j];
this->conector[i].description[this->conector[i].description_length]='\0';
this->conector[i].function_length=op.conector[i].function_length;
this->conector[i].function_name=new char[this->conector[i].function_length+1];
for(j=0;j<this->conector[i].function_length;j++)
this->conector[i].function_name[j]=op.conector[i].function_name[j];
this->conector[i].function_name[this->conector[i].function_length]='\0';
this->conector[i].in_param_cnt=op.conector[i].in_param_cnt;
this->conector[i].out_param_cnt=op.conector[i].out_param_cnt;
}
this->data_in=op.data_in;
this->hdll=op.hdll;
this->icount_in=op.icount_in;
this->iid=op.iid;
this->level=op.level;
this->libid=op.libid;
this->name_length=op.name_length;
this->cmd_name=new char[this->name_length+1];
for(i=0;i<this->name_length;i++)
this->cmd_name[i]=op.cmd_name[i];
this->cmd_name[this->name_length]='\0';
this->where_length=op.where_length;
this->cmd_where=new char[this->where_length+1];
for(i=0;i<this->where_length;i++)
this->cmd_where[i]=op.cmd_where[i];
this->cmd_where[this->where_length]='\0';
}
_declspec(dllexport) void assign(command* op0,command& op,int cmd_id)
{
op0->clsid=op.clsid;
op0->cmd_id=cmd_id;
op0->info_length=op.info_length;
op0->cmd_info=new char[op0->info_length+1];
for(unsigned int i=0;i<op0->info_length;i++)
op0->cmd_info[i]=op.cmd_info[i];
op0->cmd_info[op0->info_length]='\0';
op0->cmd_lan=op.cmd_lan;
op0->cmd_type=op.cmd_type;
op0->conector_cnt=op.conector_cnt;
for(i=0;i<op0->conector_cnt;i++)
{op0->conector[i].description_length=op.conector[i].description_length;
op0->conector[i].description=new char[op0->conector[i].description_length+1];
for(unsigned int j=0;j<op0->conector[i].description_length;j++)
op0->conector[i].description[j]=op.conector[i].description[j];
op0->conector[i].description[op0->conector[i].description_length]='\0';
op0->conector[i].function_length=op.conector[i].function_length;
op0->conector[i].function_name=new char[op0->conector[i].function_length+1];
for(j=0;j<op0->conector[i].function_length;j++)
op0->conector[i].function_name[j]=op.conector[i].function_name[j];
op0->conector[i].function_name[op0->conector[i].function_length]='\0';
op0->conector[i].in_param_cnt=op.conector[i].in_param_cnt;
op0->conector[i].out_param_cnt=op.conector[i].out_param_cnt;
}
op0->data_in=op.data_in;
op0->hdll=op.hdll;
op0->icount_in=op.icount_in;
op0->iid=op.iid;
op0->level=op.level;
op0->libid=op.libid;
op0->name_length=op.name_length;
op0->cmd_name=new char[op0->name_length+1];
for(i=0;i<op0->name_length;i++)
op0->cmd_name[i]=op.cmd_name[i];
op0->cmd_name[op0->name_length]='\0';
op0->where_length=op.where_length;
op0->cmd_where=new char[op0->where_length+1];
for(i=0;i<op0->where_length;i++)
op0->cmd_where[i]=op.cmd_where[i];
op0->cmd_where[op0->where_length]='\0';
}
char* command::get_run_info() const
{
return run_info;
}
int command::go(int funcnumber,const mydata* in, mydata* out)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
int result=0;
if(cmd_name!=NULL)
{if(cmd_type==com_std) //遵循定義的標準接口
{
CString info(cmd_name,name_length);
myinterface* face;
if(FAILED(CoInitialize(NULL)))
AfxMessageBox("組件庫初試化錯誤");
HRESULT hr=CoCreateInstance(clsid,NULL,CLSCTX_INPROC,iid,(void**)&face);
if(FAILED(hr))
AfxMessageBox(info+"模塊沒有找到");
}
else if(cmd_type==com_disp) //格式自由的派發接口
{ _MCLCONVERSION_FLAGS flags;
IMWFlags* pFlags = NULL;
disp_conector it;
disp_conector* pit=⁢
DISPID dispid;
IDispatch* dp;
CString info(cmd_name,name_length);
if(FAILED(CoInitialize(NULL)))
{AfxMessageBox("組件庫初試化錯誤");
return -1;
}
if (FAILED(CoCreateInstance(CLSID_MWFlags, NULL, CLSCTX_INPROC_SERVER,
IID_IMWFlags, (void**)&pFlags)))
{AfxMessageBox("矩陣轉換模塊沒有找到,請檢查Matlab數學庫是否正確安裝");
return -1;
};
if (FAILED(GetConversionFlags(pFlags, &flags)))
{
AfxMessageBox("Error getting data conversion flags");
return -1;
}
pFlags->Release();
HRESULT hr=CoCreateInstance(clsid,NULL,CLSCTX_INPROC,iid,(void**)&dp);
if(FAILED(hr))
{
return -1;
} //必要的準備
CString info1(conector[funcnumber].description,conector[funcnumber].description_length);
LPOLESTR lcmd_name=new unsigned short[conector[funcnumber].description_length];
char *ssss=(char*)lcmd_name;
for( int k=0;k<conector[funcnumber].description_length;k++)
lcmd_name[k]=conector[funcnumber].description[k];
hr=dp->GetIDsOfNames(IID_NULL,&lcmd_name,1,LOCALE_SYSTEM_DEFAULT,&dispid);
DWORD* dwp=(DWORD*)dp;
DWORD* vtable=(DWORD*)(*dwp);
DWORD* dw=(DWORD*)&(pit->p1i0o);
*dw=*(vtable+DISP_BASE+dispid);
static VARIANT in_bag[MAX_IN_PARAM] ;
static VARIANT out_bag[MAX_OUT_PARAM];
//InitConversionFlags(&flags);
for(k=0;k<conector[funcnumber].in_param_cnt;k++)
mxArray2Variant(in->pdata.mw[k].GetData(),in_bag+k,&flags);
int the_func_type=5*(conector[funcnumber].in_param_cnt)+conector[funcnumber].out_param_cnt;
hr=invoke(dp,pit,the_func_type,out_bag,in_bag);
mxArray *tempbag[MAX_OUT_PARAM];
for(k=0;k<MAX_OUT_PARAM;k++)
tempbag[k]=NULL;
mwArray mwbag[MAX_OUT_PARAM];
for(k=0;k<conector[funcnumber].out_param_cnt;k++)
{
mwbag[k]=mwArray(tempbag[k]);//mx結構賦予mw類以后由mw析構,切記!!!
}
// double r[10],im[10];
// mwbag[0].ExtractData(r,im);
out->mset_data(run_info,tinfo.GetLength()+4,type_mw,NULL,NULL,conector[funcnumber].out_param_cnt,mwbag);
}
else if(cmd_type==function)//普通DLL函數接口
{int i=funcnumber;
if(level>=special)
hdll=::LoadLibrary(cmd_where);
(data_in+1)->outer=TRUE;
if((conector+i)->type_in==type_dou)
{ unsigned int cnt;
double bag;
(conector+i)->pfunc.doufunc=(pdaoai)::GetProcAddress(hdll,(conector+i)->description);
if((conector+i)->pfunc.doufunc!=NULL)
{
result=(conector+i)->pfunc.doufunc(&bag,&cnt,in->pdata.dou,in->the_length);
out->set_data(NULL,NULL,type_dou,cnt,&bag);
}
else
{CString info((conector+i)->function_name,(conector+i)->function_length);
AfxMessageBox(info+"函數沒有找到");
}
}
else if((conector+i)->type_in==type_mw)
{unsigned int cnt;
mwArray bag;
(conector+i)->pfunc.mwfunc=(pdmwomwi)::GetProcAddress(hdll,(conector+i)->description);
if((conector+i)->pfunc.mwfunc!=NULL)
{
result=(conector+i)->pfunc.mwfunc(&bag,&cnt,in->pdata.mw,in->the_length);
double r[4],i[4];
bag.ExtractData(r,i);
out->mset_data(NULL,NULL,type_mw,NULL,NULL,cnt,&bag);
}
else
{CString info((conector+i)->function_name,(conector+i)->function_length);
AfxMessageBox(info+"函數沒有找到");
}
::FreeLibrary(hdll);
hdll=NULL;
}
// else if((conector+i)->type_in==type_var) //暫時不支持
// (conector+i)->pfunc.varfunc=(pdvovi)::GetProcAddress(hdll,(conector+i)->description);
}
}
return result;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -