显示标签为“ActiveX”的博文。显示所有博文
显示标签为“ActiveX”的博文。显示所有博文

星期二, 十月 03, 2006

COM中讨厌的 RtlSizeHeap, ActiveX host in IE

http://www.codeguru.com/forum/showthread.php?t=43648

内存管理的问题

I didn't have time to get to the bottom of this --- though I suspect that it's related to COM BSTRs (or VARIANTS) and the handling/deallocation of them. There are some strict rules as to who has to free BSTR memory -- check out MSDN to get some more info on this. I've also found that heap management under Windows 2000 is quite a bit different than NT 4. There seems to be more heap optimization going on -- which causes some code (probably written incorrectly!) to blow that worked fine in NT4.

In the case of my original post, I didn't have time to go back and trace everything out, so I brought the VC++ ADO COM object into my source as a CLASS module instead of a COM object (which in this one case cleared things up). As noted above, I'm sure the issues were mine -- and related to how BSTRs or variants were being handled. Sure seems strange that ALL the addresses for all three problems were the same! Anybody have any other ideas?

下面是一个低级错误:
>>I get the above error when i return a string parameter
>>of LPCSTR type

Is it a string literal? IOW, are you doint sth. like

LPCSTR foo()
{
LPCSTR _p = "123";

return _p;
}

If so, change it to use a non-const memory area, e.g.

LPCSTR foo()
{
LPCSTR _a [] = "123";

return _a;
}

我想,道理是一样的不过,出现问题的情况会比上面复杂的多!

http://msdn2.microsoft.com/en-us/library/ms235460(d=ide).aspx

异质编译连接的问题

http://discussms.hosting.lsoft.com/SCRIPTS/WA-MSD.EXE?A2=ind0112a&L=atl&D=0&T=0&P=4234

又一个,同一内存释放了两次

而我碰到的问题不在上面的范畴之内,一个ActiveX的事件,用attachEvent多次处理后,会随机产生RtlSizeHeap错误,改用[script for="ID" event="Event" language="javascript"][/script],错误消失,在attachEvent的时候对传给事件处理程序的参数被修改了,所以产生。但为什么前者会产生这种现象呢,还不清楚!

后来在google里面找ActiveX attachEvent的相关资料,大多是关于标准HTML元素的,对ActiveX较少,不过找到一本不错的书! 构建WEB应用程序的人非常值得去读一下!http://book.itzero.com/read/others/McGraw.Hill.Osborne.JavaScript.2.0.The.Complete.Reference.Second.Edition.eBook-LiB_html/8166final/toc.html

下面的链接简单介绍了ActiveX事件处理的方法!
http://discuss.develop.com/archives/wa.exe?A2=ind0212b&L=atl&T=0&H=1&P=4599

LuaCOM for Lua 5.1.1 Fixed!

下面的话是我理解错误造成的!
除了上面引用的 LuaCOM - more questions 中所解决的问题外,LuaCOM 在 Lua 5.1.1中还有一个比较严重的问题,那就是 接口 参数传入有问题,具体原因还不太清楚,可能是lua 5.1与lua 5.0在传入函数参数时,对于堆栈的操作发生改变,类似于下面的代码需要修正!


1 多处定义的 self_param=1,并未在其他地方使用,干脆移除,要不干扰我们对代码的理解!
2 文中多处定义的 const int first_param = 2; 会在COM接口lua 5.1中造成第一个参数丢失,所以改成const int first_param = 1
3 const int num_params = luaCompat_getNumParams(L, 4) - 1; 由于first_param 从2改为1,所以把它改成const int num_params = luaCompat_getNumParams(L, 4);

基本上就这样,还需要更多的验证,另外对luacom的改动,需要内lua的VM机制与COM机制有比较深入的认识,说实话,这两件事情都比较复杂,另外由于luacom的不跨平台性,用ATL与luabind来重新实现应该是比较好的选择,代码量可能会更小!

修改,上面的方法存在问题,如果是用obj.method的方法来调用,需要用上面的方法修改,如果用obj:Method的方法来调用的话,就不需要改拉!

LuaCOM - more questions

LuaCOM - more questions

Click to flag this post

by Terry Bayne Jan 31, 2006; 09:26pm :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Good Morning.

I've started using LuaCOM and I have a few questions. I am not a COM guru so please excuse my ignorance.

I am trying to build on the examples from the LuaCOM documentation, and in doing so I have no problem opening up Microsoft Word. The problem comes when I try to create a new document - most of the examples on the web do something like this:

word = luacom.CreateObject("Word.Application")
assert(word)
word.visible = true
-- Works good up to this point
doc = word.Documents.Add()

The last statement fails. I've tried passing parameters, even tried this:

word = luacom.CreateObject("Word.Application")
mt = luacom.CreateObject("type.missing")
assert(word)
word.visible = true
-- Works good up to this point
doc = word.Documents.Add(mt,mt,mt,mt)

All this gets me is a type mismatch error.

Any ideas?

Thanks
Terry


Re: LuaCOM - more questions

Click to flag this post

by Fabio Mascarenhas Jan 31, 2006; 10:08pm :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Hi, Terry,

This:

> doc = word.Documents.Add()

should be this:

doc = word.Documents:Add()

Method calls use ':'. Reading and writing properties use '.'.

--
Fabio Mascarenhas

On 1/31/06, Terry Bayne <tbayne@...> wrote:
> Good Morning.
>
> I've started using LuaCOM and I have a few questions. I am not a COM guru so please excuse my ignorance.
>when I try to create a new document - most of the examples on the web
do >something like this:
>
> word = luacom.CreateObject("Word.Application")
> assert(word)
> word.visible = true
> -- Works good up to this point
> doc = word.Documents.Add()
>
> The last statement fails. I've tried passing parameters, even tried this:
> All this gets me is a type mismatch error.

LuaCOM - more questions

Click to flag this post

by Michael Cumming Jan 31, 2006; 11:01pm :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Terry,

Its

doc = word.Documents:Add()

note the ':' not '.'

Mike

Re: LuaCOM - more questions

Click to flag this post

by Terry Bayne Feb 01, 2006; 12:10am :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Fabio,

Thanks for spotting that, but still getting a type mismatch error:

LUA: Calling word.Documents:Add
Error executing lua code: [COM error:(E:\Blackdog\kibble\trunk\luacom\src\library\tLuaCOM.cpp,403):Type mismatch.]

Here is the lua code I am running:

word = luacom.CreateObject("Word.Application")
MT = luacom.CreateObject("type.missing")
assert(word)word.visible = true
print("Calling word.Documents:Add")
doc = word.Documents:Add()
print("Back from Documents:Add()")

Any ideas?

Also I have tried passing MT to the Add() call like so:

doc = word.Documents:Add(MT,MT,MT,MT)

Thanks

On Tue, 31 Jan 2006 12:08:11 -0200, Fabio Mascarenhas wrote:
>> Hi, Terry,
>>
>> This:
>>
>>>> doc = word.Documents.Add()
>>>>
>> should be this:
>>
>> doc = word.Documents:Add()
>>
>> Method calls use ':'. Reading and writing properties use '.'.
>>
>> --
>> Fabio Mascarenhas
>>
>> On 1/31/06, Terry Bayne <tbayne@...> wrote:
>>
>>>> Good Morning.
>>>>
>>>> I've started using LuaCOM and I have a few questions. I am not
>>>> a COM guru so please excuse my ignorance.
>>>> when I try to create a new document - most of the examples on
>>>> the web
>>>>
>> do >something like this:
>>
>>>> word = luacom.CreateObject("Word.Application") assert(word)
>>>> word.visible = true -- Works good up to this point doc =
>>>> word.Documents.Add()
>>>>
>>>> The last statement fails. I've tried passing parameters, even
>>>> tried this: All this gets me is a type mismatch error.


RE: LuaCOM - more questions

Click to flag this post

by Ignacio Burgueño Feb 01, 2006; 01:16am :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Hi Terry. What version of LuaCOM are you using? Just tested your sample code
using luaCom 1.2 and Office 2003 and it worked fine.



> -----Original Message-----
> From: lua-bounces@...
> [mailto:lua-bounces@...] On Behalf Of Terry Bayne
> Sent: Tuesday, January 31, 2006 1:15 PM
> To: Lua list
> Subject: Re: LuaCOM - more questions
>
> Fabio,
>
> Thanks for spotting that, but still getting a type mismatch error:
>
> LUA: Calling word.Documents:Add
> Error executing lua code: [COM
> error:(E:\Blackdog\kibble\trunk\luacom\src\library\tLuaCOM.cpp
> ,403):Type mismatch.]
>
> Here is the lua code I am running:
>
> word = luacom.CreateObject("Word.Application")
> MT = luacom.CreateObject("type.missing")
> assert(word)word.visible = true
> print("Calling word.Documents:Add")
> doc = word.Documents:Add()
> print("Back from Documents:Add()")
>
> Any ideas?
>
> Also I have tried passing MT to the Add() call like so:
>
> doc = word.Documents:Add(MT,MT,MT,MT)
>
> Thanks

RE: LuaCOM - more questions

Click to flag this post

by Terry Bayne Feb 01, 2006; 01:41am :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Ignacio,

Hi, thank you for taking the time to look at this. I am using LUACom 1.3 with Office 2003 and LUA 5.0.2.

Terry

On Tue, 31 Jan 2006 15:12:24 -0300, Ignacio Burgueño wrote:
>> Hi Terry. What version of LuaCOM are you using? Just tested your
>> sample code using luaCom 1.2 and Office 2003 and it worked fine.
>>
>>
>>>> -----Original Message-----
>>>> From: lua-bounces@...
>>>> [mailto:lua-bounces@...] On Behalf Of Terry
>>>> Bayne Sent: Tuesday, January 31, 2006 1:15 PM To: Lua list
>>>> Subject: Re: LuaCOM - more questions
>>>>
>>>> Fabio,
>>>>
>>>> Thanks for spotting that, but still getting a type mismatch
>>>> error:
>>>>
>>>> LUA: Calling word.Documents:Add
>>>> Error executing lua code: [COM
>>>> error:(E:\Blackdog\kibble\trunk\luacom\src\library\tLuaCOM.cpp
>>>> ,403):Type mismatch.]
>>>>
>>>> Here is the lua code I am running:
>>>>
>>>> word = luacom.CreateObject("Word.Application")
>>>> MT = luacom.CreateObject("type.missing")
>>>> assert(word)word.visible = true
>>>> print("Calling word.Documents:Add")
>>>> doc = word.Documents:Add()
>>>> print("Back from Documents:Add()")
>>>>
>>>> Any ideas?
>>>>
>>>> Also I have tried passing MT to the Add() call like so:
>>>>
>>>> doc = word.Documents:Add(MT,MT,MT,MT)
>>>>
>>>> Thanks


RE: LuaCOM - more questions

Click to flag this post

by Ignacio Burgueño Feb 01, 2006; 05:04am :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

Well. I compiled a debug version of luacom 1.3 (as of 2005-02-28) and it
does not work.
Indeed, the code fails when calling the Add method from the Word.Document
class
Its signature is:

HRESULT Add(
[in, optional] VARIANT* Template,
[in, optional] VARIANT* NewTemplate,
[in, optional] VARIANT* DocumentType,
[in, optional] VARIANT* Visible,
[out, retval] Document** prop);

I don't know if luacom 1.3 introduced a new approach to handle optional
parameters, but I think that the problem lies in the function
tLuaCOMTypeHandler::fillDispParams
At line 943, there's this code:

else if(!byref) // here we filter the optional out params (treated
below)
{
// assumes that a parameter is expected but has not been found

var.vt = VT_ERROR;
var.scode = DISP_E_PARAMNOTFOUND;
}

if(!byref || var.vt == VT_ERROR)
{
VariantCopy(&r_rgvarg[i], &var);
VariantClear(&var);
}

byref is true (it was set at line 911), and the parameter is [in] but it
seems that that case isn't handled properly. It should pass a Variant with
VT_ERROR and DISP_E_PARAMNOTFOUND.
I'm not quite sure of how to fix this properly.
Changing line 943 to this works fine:
else if(byref) // here we filter the optional out params (treated
below)
But I didn't check if that breaks other calls.

Regards,

Ignacio Burgueño
Desarrollo - Tecnolink S.A.
ignacio@...

Tel: +598 2 614-1003
www.inConcertCC.com


> -----Original Message-----
> From: lua-bounces@...
> [mailto:lua-bounces@...] On Behalf Of Terry Bayne
> Sent: Tuesday, January 31, 2006 2:45 PM
> To: Lua list
> Subject: RE: LuaCOM - more questions
>
> Ignacio,
>
> Hi, thank you for taking the time to look at this. I am
> using LUACom 1.3 with Office 2003 and LUA 5.0.2.
>
> Terry
>
> On Tue, 31 Jan 2006 15:12:24 -0300, Ignacio Burgueño wrote:
> >> Hi Terry. What version of LuaCOM are you using? Just tested your
> >> sample code using luaCom 1.2 and Office 2003 and it worked fine.
> >>
> >>
> >>>> -----Original Message-----
> >>>> From: lua-bounces@...
> >>>> [mailto:lua-bounces@...] On Behalf Of Terry
> >>>> Bayne Sent: Tuesday, January 31, 2006 1:15 PM To: Lua list
> >>>> Subject: Re: LuaCOM - more questions
> >>>>
> >>>> Fabio,
> >>>>
> >>>> Thanks for spotting that, but still getting a type mismatch
> >>>> error:
> >>>>
> >>>> LUA: Calling word.Documents:Add
> >>>> Error executing lua code: [COM
> >>>> error:(E:\Blackdog\kibble\trunk\luacom\src\library\tLuaCOM.cpp
> >>>> ,403):Type mismatch.]
> >>>>
> >>>> Here is the lua code I am running:
> >>>>
> >>>> word = luacom.CreateObject("Word.Application")
> >>>> MT = luacom.CreateObject("type.missing")
> >>>> assert(word)word.visible = true
> >>>> print("Calling word.Documents:Add")
> >>>> doc = word.Documents:Add()
> >>>> print("Back from Documents:Add()")
> >>>>
> >>>> Any ideas?
> >>>>
> >>>> Also I have tried passing MT to the Add() call like so:
> >>>>
> >>>> doc = word.Documents:Add(MT,MT,MT,MT)
> >>>>
> >>>> Thanks
>
>
>
>

RE: LuaCOM - more questions

Click to flag this post

by Shaun-7 Feb 01, 2006; 05:23am :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message


> I don't know if luacom 1.3 introduced a new approach to handle optional
> parameters, but I think that the problem lies in the function
> tLuaCOMTypeHandler::fillDispParams
> At line 943, there's this code:

I had exactly the same problem and implemented a fix exactly like you
suggested.

I sent an email to the maintainer, Fabio Mascarenhas, at the time, but
don't think I ever heard anything back.

Cheers,
Shaun

RE: LuaCOM - more questions

Click to flag this post

by Terry Bayne Feb 01, 2006; 07:43am :: Rate this Message: Click to rate as Poor PostClick to rate as Below Average PostClick to rate as Average PostClick to rate as Above Average PostClick to rate as Excellent Post Click to clear rating - Use ratings to moderate (?)

Reply | Reply to Author | View Threaded | Link to this Message

That did seem to solve the problem! Thanks to both you and Shaun for your help!

Terry

On Tue, 31 Jan 2006 19:07:52 -0300, Ignacio Burgueño wrote:
>> Well. I compiled a debug version of luacom 1.3 (as of 2005-02-28)
>> and it does not work.
>> Indeed, the code fails when calling the Add method from the
>> Word.Document class Its signature is:
>>
>> HRESULT Add(
>> [in, optional] VARIANT* Template,
>> [in, optional] VARIANT* NewTemplate,
>> [in, optional] VARIANT* DocumentType,
>> [in, optional] VARIANT* Visible,
>> [out, retval] Document** prop);
>>
>> I don't know if luacom 1.3 introduced a new approach to handle
>> optional parameters, but I think that the problem lies in the
>> function tLuaCOMTypeHandler::fillDispParams At line 943, there's
>> this code:
>>
>> else if(!byref) // here we filter the optional out params (treated
>> below) {
>> // assumes that a parameter is expected but has not been found
>>
>> var.vt = VT_ERROR;
>> var.scode = DISP_E_PARAMNOTFOUND;
>> }
>>
>> if(!byref || var.vt == VT_ERROR)
>> {
>> VariantCopy(&r_rgvarg[i], &var);
>> VariantClear(&var);
>> }
>>
>> byref is true (it was set at line 911), and the parameter is [in]
>> but it seems that that case isn't handled properly. It should pass
>> a Variant with VT_ERROR and DISP_E_PARAMNOTFOUND. I'm not quite
>> sure of how to fix this properly. Changing line 943 to this works
>> fine:
>> else if(byref) // here we filter the optional out params (treated
>> below) But I didn't check if that breaks other calls.
>>
>> Regards,
>>
>> Ignacio Burgueño
>> Desarrollo - Tecnolink S.A.
>> ignacio@...
>>
>> Tel: +598 2 614-1003
>> www.inConcertCC.com
>>
>>
>>>> -----Original Message-----
>>>> From: lua-bounces@...
>>>> [mailto:lua-bounces@...] On Behalf Of Terry
>>>> Bayne Sent: Tuesday, January 31, 2006 2:45 PM To: Lua list
>>>> Subject: RE: LuaCOM - more questions
>>>>
>>>> Ignacio,
>>>>
>>>> Hi, thank you for taking the time to look at this. I am using
>>>> LUACom 1.3 with Office 2003 and LUA 5.0.2.
>>>>
>>>> Terry
>>>>
>>>> On Tue, 31 Jan 2006 15:12:24 -0300, Ignacio Burgueño wrote:
>>>>
>>>>>> Hi Terry. What version of LuaCOM are you using? Just tested
>>>>>> your sample code using luaCom 1.2 and Office 2003 and it
>>>>>> worked fine.
>>>>>>
>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: lua-bounces@...
>>>>>>>> [mailto:lua-bounces@...] On Behalf Of
>>>>>>>> Terry Bayne Sent: Tuesday, January 31, 2006 1:15 PM To:
>>>>>>>> Lua list Subject: Re: LuaCOM - more questions
>>>>>>>>
>>>>>>>> Fabio,
>>>>>>>>
>>>>>>>> Thanks for spotting that, but still getting a type
>>>>>>>> mismatch error:
>>>>>>>>
>>>>>>>> LUA: Calling word.Documents:Add
>>>>>>>> Error executing lua code: [COM
>>>>>>>> error:(E:\Blackdog\kibble\trunk\luacom\src\library\tLuaCOM.cpp ,403):
>>>>>>>> Type mismatch.]
>>>>>>>>
>>>>>>>> Here is the lua code I am running:
>>>>>>>>
>>>>>>>> word = luacom.CreateObject("Word.Application")
>>>>>>>> MT = luacom.CreateObject("type.missing")
>>>>>>>> assert(word)word.visible = true
>>>>>>>> print("Calling word.Documents:Add")
>>>>>>>> doc = word.Documents:Add()
>>>>>>>> print("Back from Documents:Add()")
>>>>>>>>
>>>>>>>> Any ideas?
>>>>>>>>
>>>>>>>> Also I have tried passing MT to the Add() call like so:
>>>>>>>>
>>>>>>>> doc = word.Documents:Add(MT,MT,MT,MT)
>>>>>>>>
>>>>>>>> Thanks