 |
|
 |
Hello,
I try to create my own Class (a kind of another SimpleObject) in the ScriptTestLib to add new functions in the Script Editor ...
At first, I added new functions in the actual SimpleObject Class ... no problem it works great. I did it by using the "Add Method" in the COM wrapper then I checked that everything was ok in the ScriptTest.odl. I can see my new fucntions in the ScriptEditor, cool.
Now I create a new Class in the ScriptTest project. I choose a MFC Class and I tick the "automation" support.
The new Class is created and I can see in ScriptTest.odl the dispatch interface for it. Then, as above, I add a fucntion with "Add Method" ... I can see now my new method listed under ScripTestLib/IMyNewClass, others are under ScriptTestLib/ISimpleObject. So far so good.
Then, I add in my InitDialog the famous line:
scripter.AddObject("MyNewClass",m_myNewClass.GetIDispatch(TRUE));
In the Script Editor, I can indeed see "MyNewClass" but not method available when I type MyNewClass. ...
So I guess I do something wrong ... does anyone could help me ?
Thanks in adavnce and thanks Alex for your great job.
Brestian
|
|
|
|
 |
|
 |
hello,Brestian
I meet the same problem as yours. Please tell me if you fixed it.
thanks a lot.
Tom
|
|
|
|
 |
|
 |
i meet this problem too,i rebuild all project,then well done!
|
|
|
|
 |
|
 |
Should this work with multithreaded apps, and if not, can anyone point me in the right direction? Using the SimpleDialog class in the included source, when I try to run FireValueChanged from another thread, I get some weird error that I cant trace b\c its in the vbscript.dll. The last line to be run is Invoke in the CCmdTargetPlus script. I assume PostMessage to the main thread would fix it, but that kind of defeats the purpose of multithreading in my case. I am a newb to automation and OLE and stuff, so this may be a stupid question to those who arent.
Thanks for the awesome code.
|
|
|
|
 |
|
 |
I developed an application that can be programmed using automation.
From Visual Basic I can create the document and call to all methods and properties.
i.e.: Dim doc as BaseMap.Document
Set doc = CreateObject("BaseMap.Document")
doc.Show = True
How should I use CScripter instead of Visual Basic?
Cordial regards from Argentina
Daniel Remedi
|
|
|
|
 |
|
 |
I am trying to incorporate your code into my MFC dialog. I was unable to compile it due to the error:
scripttestDlg.obj : error LNK2001: unresolved external symbol "public: int __thiscall CScripter::CreateEngine(class ATL::CStringT > >)" (?CreateEngine@CScripter@@QAEHV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
Any ideas why this is happening? I am building a release build and pointing to the library file in the LibR directory. I am using Visual Studio 2005. Is it possible the libraries need to be rebuilt for my version of VS?
Thanks
|
|
|
|
 |
|
 |
Yup they need rebuilt w/out using CString as parameters.
See the link...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vclrfatlcompatibilityissues.asp
Maybe I can find Visual C++ 6.0 and create a wrapper around the CScripter class which converts the CString variable to something else and rebuild the DLL for use in 8.0.
|
|
|
|
 |
|
 |
I created a wrapper for this, so now it can be used in VS 2005 if anybody is interested.
|
|
|
|
 |
|
 |
Hi,
Got the same problem to compile under .NET ... could you share your wrapper ?
You can send it to me at brestian-at-bluewin-dot-ch
Thanks a lot !
Regards
|
|
|
|
 |
|
 |
Hi,
Same thing for me, I would really appreciate if you can send your wrapper to :
seb79fr at yahoo.fr
Thanks a lot,
Regards
|
|
|
|
 |
|
 |
Hello Alex,
Thank you for your script control.
But if I put my recompiled lib (either debug/release) to demo folder, I can not recompile demo. If I copy all headers in inc folder of source to same folder of demo, demo does not compile.
I checked the header files and found scripter.h in both folder are different and in demo's inc folder it has cmdtargetplus.h file but in inc folder of source it does. Then I copied all header from demo to source, I was not able to compile source anymore.
If you have new update of the project, can you send to my email address:
zhaozh@telus.net
Thanks a lot!
Stephen
|
|
|
|
 |
|
 |
The most recent headers are in the source zip folder.
The cmdtargetplus.h belongs only to the demo project and is NOT a component of the script control. (It's there for the sample ActiveX object).
You should copy the headers from the source zip to the demo project and it should compile.
Creative minds - create creative creations!
|
|
|
|
 |
|
 |
When you creates a new Object (OCX) and exit the program you will get a memory leaks for that object.
I found that its due to having getting the Unknown interface and give its value to the passing pointer in the function but never rlease this pointer I have copied the function and mark the lines I have added to avoid the memory leaks.
STDMETHODIMP CScripter::XActiveScriptSite::GetItemInfo(
/* [in] */ LPCOLESTR pstrName,
/* [in] */ DWORD dwReturnMask,
/* [out] */LPUNKNOWN* ppiunkItem,
/* [out] */LPTYPEINFO* ppti)
{
HRESULT hr = S_OK;
METHOD_PROLOGUE(CScripter, ActiveScriptSite)
USES_CONVERSION;
if (dwReturnMask & SCRIPTINFO_ITYPEINFO)
{
if (!ppti)
return E_INVALIDARG;
*ppti = NULL;
}
if (dwReturnMask & SCRIPTINFO_IUNKNOWN)
{
if (!ppiunkItem)
return E_INVALIDARG;
*ppiunkItem = NULL;
}
IDispatch* pDisp;
if (!(pThis->mapNamedItems.Lookup(OLE2CT(pstrName), (void*&) pDisp)))
{
return TYPE_E_ELEMENTNOTFOUND;
}
LPUNKNOWN pUnk = pDisp;
if (dwReturnMask & SCRIPTINFO_ITYPEINFO)
{
// Use IProvideClassInfo to get ITypeInfo of coclass!
IProvideClassInfo *pci = NULL;
hr = pUnk->QueryInterface(IID_IProvideClassInfo, (void**)&pci);
if (SUCCEEDED(hr) && pci)
hr = pci->GetClassInfo(ppti);
///////////////////freen the IUnknown interface /////////////////////////
pUnk->Release() ;
/////////////////////////////////////////////
if (FAILED(hr))
{
hr = pDisp->GetTypeInfo(0,0,ppti);
if (FAILED(hr))
return E_FAIL;
}
}
if (dwReturnMask & SCRIPTINFO_IUNKNOWN)
{
*ppiunkItem = pUnk;
///////////////////freen the IUnknown interface /////////////////////////
pUnk->Release() ;
/////////////////////////////////////////////
(*ppiunkItem)->AddRef(); // because returning
}
return S_OK;
}
Also I have changes a bitthe function CColorizer::SetLineColors to support object name coloring and changed the color in the Colorize header file
#define KEYWORD_COLOR RGB(0,0,160)
#define COMMENT_COLOR RGB(0,120,0)
#define CONSTANT_COLOR RGB(128,128,0)
#define OBJECT_COLOR RGB(128,0,0)
#define FUNCTION_COLOR RGB(44,130,163)
#define ERROR_COLOR RGB(255,0,0)
#define NORMAL_COLOR RGB(0,0,0)
void CColorizer::SetLineColors(int lineNum, CString &csString, vector& colors)
{
// nothing to do
if (csString.GetLength() == 0)
{
colors.clear();
return;
}
// one COLORREF per input char
colors.resize(csString.GetLength());
// look for keywords
CString word;
word = csString;
word.TrimLeft();
word.TrimRight();
word = word.Left(3);
//set the line to all black
int k = 0;
int j = csString.GetLength();
COLORREF color = NORMAL_COLOR;
for (int i = 0; i < j; i++)
{
if (csString[i] == '\'')
{
color = COMMENT_COLOR;
}
if (lineNum == pScripter->errLine)
{
color = ERROR_COLOR;
}
colors.at(i) = color;
}
BOOL bFoundWord = FALSE ;
COLORREF colorFoundWord = NORMAL_COLOR ;
// do keyword coloring and auto-case correction
while( k < j)
{
// find "words" (sequences of alpha-numeric characters)
word.Empty();
while ((k < j) && (!__iscsym(csString.GetAt(k))))
{
k++;
}
int s = k;
while ((k < j) && (__iscsym(csString.GetAt(k))))
{
word = word + csString.GetAt(k);
k++;
}
int e = k;
word.TrimLeft();
word.TrimRight();
bFoundWord = TRUE ;
do
{
if (IsKeyWord(word))
{
colorFoundWord = KEYWORD_COLOR ;
break ;
}
if (pScripter->IsLangKeyWord(word))
{
colorFoundWord = FUNCTION_COLOR ;
break ;
}
if (pScripter->IsObject(word))
{
colorFoundWord = OBJECT_COLOR ;
break ;
}
bFoundWord = FALSE ;
}while (0) ;
if (bFoundWord == TRUE)
{
int l = 0;
for(i = s; i < e; i++)
{
l++;
if (colors.at(i) == NORMAL_COLOR)
colors.at(i) = colorFoundWord;
}
if (pScripter->m_bCapitalizeScript)
{
csString.Delete(s, e - s);
csString.Insert(s, word);
}
}
}
}
|
|
|
|
 |
|
 |
I found by myself a bug when running the script twice it cause crash so dont chnage as requested. I am cheking it again, Sorry for misleading you but it is cause a memory leaks anyway, Need fixes on that.
|
|
|
|
 |
|
 |
When I creates a new function in the SimpleObject and it appear when ever needed in the source files but I never saw it in the script editor. i.e I have added function long MoveMotor(double dbPosition) but this function never apear in the script editor.
Can you tell me why ???
Please add a sample of any function that will shows up in the script editor
Thanks
Arie
Arie Levy
|
|
|
|
 |
|
 |
The function should be a COM method and added via Add Method / Add Property in the COM wrapper.
Meaning it must appear in the IDL file. (Look at the IDL file for more info.)
Creative minds - create creative creations!
|
|
|
|
 |
|
 |
Yeap, have you never considered Lua : http://www.lua.org/ ?
Check the code wrappers there : http://lua-users.org/wiki/LuaAddons
Kochise
In Code we trust !
|
|
|
|
 |
|
 |
I have considered several scripting languages but eventually i have stoped at the choise of JScript and VBScript since they are widely supported, documented and knows to many programmes, also they are supported via ActiveX, and most importand it suited the project i was working on , by the time i made this scrip editor.
Creative minds - create creative creations!
|
|
|
|
 |
|
 |
The code:
scripter.scriptText = "MsgBox \"Test message\"";
doesn't work.
I modified the script test project and insert
scripter.scriptText = "MsgBox \"Test message\"";
into the CScriptTestDlg::OnInitDialog() before return TRUE.
Then, the application crashed.
I am sure I have use a debug version DLL and EXE files.
Any suggestion?
|
|
|
|
 |
|
 |
Hi,
I would like to use your code, so I prepared some CCmdTargetPlus-derived objects, but their events are not seen in the editor list. Moreover, when I access them, my app chashes when I try to unload the script interface. Have you got any idea on when the problem could lie over?
I checked several times the source of your SimpleObject object and they seems the same!
Any help is appreciated.
Thanks a lot.
Regards,
Andrea
|
|
|
|
 |
|
 |
I should see you code to identify the problem... Since it seems that no problem should occure... , maybe it has to do with different SDK versions?
Creative minds - create creative creations!
|
|
|
|
 |
|
 |
Hi Alex,
sorry I completely forgot to have post this message. It was 7months ago !!!.
I succeded in use your code, and I cited you in the about box. The problem was on my mistakes in publishing COM objects using MFC. I was trying to adapt an existing, non-COM MFC project and I made some mistakes.
Thanks a lot.
Regards,
Andrea
|
|
|
|
 |
|
 |
You're welcome , I actually posted only now, since somebody else asked the same question...
It seems I have somehow overlooked your post the first time, sorry about that.
Glad you succeeded and using the component.
Best regards,
Creative minds - create creative creations!
|
|
|
|
 |
|
 |
I build a debug version of ScriptEditor.dll. When I run the ScriptTest.exe using the debug version of ScriptEditor.dll, the program crashed, the message is "Debug Assertion Failed File:afxstate.cpp Line:262" does anyone known what happend?
any suggestion will be appreciate!
|
|
|
|
 |
|
 |
Are you able to build this on VC 7.1?
I get errors trying to build the demo app:
d:\code\scripttest\simpleobject.cpp(80) : error C2039: 'GetThisEventMap' : is not a member of 'CCmdTargetPlus'
d:\code\scripttest\cmdtargetplus.h(11) : see declaration of 'CCmdTargetPlus'
It seems to think the simple object is being built with _AFXDLL defined.
The dll itself builds fine.
regards,
rp
|
|
|
|
 |