///////////////////////////////////////////////////// ///////////////////////////////////////////////////// // // LoadUnicodeString // ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// #include "CKAll.h" CKObjectDeclaration *FillBehaviorLoadUnicodeStringDecl(); CKERROR CreateLoadUnicodeStringProto(CKBehaviorPrototype **); int LoadUnicodeString(const CKBehaviorContext& behcontext); CKObjectDeclaration *FillBehaviorLoadUnicodeStringDecl() { CKObjectDeclaration *od = CreateCKObjectDeclaration("Load Unicode String"); od->SetDescription("Loads an unicode string from a file."); /* rem: In: triggers the process.
Out: is activated when the process is completed.

File: name of the file containing the string to load. Must be given as an absolute path or relative to the .cmo or the .exe.

String: the loaded string.
*/ od->SetCategory("Interface/Text"); od->SetType( CKDLL_BEHAVIORPROTOTYPE); od->SetGuid(CKGUID(0x391555d7,0x42f25aae)); od->SetAuthorGuid(VIRTOOLS_GUID); od->SetAuthorName("Virtools"); od->SetVersion(0x00010000); od->SetCreationFunction(CreateLoadUnicodeStringProto); od->SetCompatibleClassId(CKCID_BEOBJECT); return od; } CKERROR CreateLoadUnicodeStringProto(CKBehaviorPrototype **pproto) { CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Load Unicode String"); if(!proto) return CKERR_OUTOFMEMORY; proto->DeclareInput("In"); proto->DeclareOutput("Out"); proto->DeclareOutput("File Error"); proto->DeclareInParameter("File",CKPGUID_STRING); proto->DeclareOutParameter("UString",CKPGUID_UNICODESTRING); proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); proto->SetFunction(LoadUnicodeString); *pproto = proto; return CK_OK; } int LoadUnicodeString(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; /// // Input / Outputs beh->ActivateInput(0,FALSE); CKSTRING string = (CKSTRING)beh->GetInputParameterReadDataPtr(0); XString filename(string); behcontext.Context->GetPathManager()->ResolveFileName(filename,DATA_PATH_IDX,-1); FILE* file = fopen(filename.Str(),"r"); if (file) { beh->ActivateOutput(0); fseek(file,0,SEEK_END); long size = ftell(file); fseek(file,0,SEEK_SET); short* text = new short[size/2+1]; // we read from the file int realcount = 0; if (size) realcount = fread(text,1,size,file); // eof text[realcount/2] = L'\0'; beh->SetOutputParameterValue(0,text,realcount+2); fclose(file); delete [] text; } else { beh->ActivateOutput(1); } return CKBR_OK; }