Opened 16 years ago
Closed 15 years ago
#1410 closed Bug (Fixed)
Using Pointer type with COM-object throws error.
| Reported by: | monoceres | Owned by: | Jon |
|---|---|---|---|
| Milestone: | 3.3.7.9 | Component: | AutoIt |
| Version: | 3.3.3.3 | Severity: | None |
| Keywords: | com pointer idispatch | Cc: |
Description
AutoIt doesn't seem to have any code dealing with variables of pointer type when using COM, the following simple example throws com error 00000005.
$oMyError = ObjEvent("AutoIt.Error", "_Au3Obj_Err")
Func _Au3Obj_Err()
MsgBox(48, 'COM Error', 'An error occured:' & @CRLF & $oMyError.description & @CRLF & _
"err.number is: " & @TAB & hex($oMyError.number,8))
EndFunc ;==>_Au3Obj_Err
$sh = ObjCreate("ScriptControl")
$sh.Language="VbScript"
$sh.Eval(Ptr(0))
Attachments (0)
Change History (6)
comment:1 by , 16 years ago
follow-up: 3 comment:2 by , 16 years ago
The example is bad. This example is straight forward and fails, too.
$oMyError = ObjEvent("AutoIt.Error", "_Au3Obj_Err")
Func _Au3Obj_Err()
MsgBox(48, 'COM Error', 'An error occured:' & @CRLF & $oMyError.description & @CRLF & _
"err.number is: " & @TAB & hex($oMyError.number,8))
EndFunc ;==>_Au3Obj_Err
$oDict = ObjCreate("Scripting.Dictionary")
; just to show the objetc works:
$oDict.add("valname", "test")
MsgBox(0, 'The object works:', "'valname' has the value: " & $oDict.Item('valname'))
;Error (crash without ErrorHandler):
$oDict.add("ptr", Ptr(1234)) ; save a pointer in the dictionary object
MsgBox(0, 'Ptr does not work:', "'ptr' has the value: " & $oDict.Item('ptr'))
follow-up: 4 comment:3 by , 16 years ago
Replying to ProgAndy:
The example is bad. This example is straight forward and fails, too.
I see what you mean, but comment on the 1st example applies here too: you convert the parameter to VT_PTR and the COM object tries to read the memory from that pointer (not the pointer value) which results in a crash. Not only you both supply an imaginary (invalid) memory address, I would also suspect no normally programmed COM component (at least none I've ever encountered) would expect VT_PTR and would know what do with it.
comment:4 by , 16 years ago
Replying to doudou:
Replying to ProgAndy:
The example is bad. This example is straight forward and fails, too.
I see what you mean, but comment on the 1st example applies here too: you convert the parameter to VT_PTR and the COM object tries to read the memory from that pointer (not the pointer value) which results in a crash. Not only you both supply an imaginary (invalid) memory address, I would also suspect no normally programmed COM component (at least none I've ever encountered) would expect VT_PTR and would know what do with it.
Come on! What the pointer points to is irrelevant. We just supplied imaginary pointers to display the issue. There are components that need the value in the field that is guarantied to be the same size as the pointer size on the system. Taking a window handle (HWND) is a good example.
comment:5 by , 16 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:6 by , 15 years ago
| Milestone: | → 3.3.7.9 |
|---|---|
| Resolution: | → Fixed |
| Status: | assigned → closed |
Fixed by revision [6124] in version: 3.3.7.9

Replying to monoceres:
What is it, what you are trying to do here?
I personally would expect this code to crash: Eval() apparently needs a string (Variant/VT_BSTR) and you submit a pointer (VT_PTR). COM error is the most harmless case here, if ScriptControl didn't validate arguments you would end up with access violation, since memory at address 0x00000000 isn't a valid read pointer.