I have a VB 6 application that uses the MSComm control to communicate
with a BootStrap Loader on a TI Chip. I would like to create a DLL so
that other applications can call the BootStrap functions. I have
created an ActiveX DLL and in order to test that this will work, I
wanted to implement just one of the functions in the ActiveX DLL and
prove it out. The function I chose is startBSL, which sets/clears the
DTR and RTS signals to tell the TI Chip to go into BootStrap mode. I
moved the function into the ActiveX DLL as a method in the BSL class.
I call the method from the original VB 6 application and pass the
MSComm control to the DLL.
ActiveX DLL contains class BSL_Class
with the following method:
Public Function startBSL (ByVal pc_comm as Object) as Boolean
VB 6 application contains an MSComm control names MSComm1
and the following code:
Public BSLDLL as BSL_Class
Set BSLDLL = New BSL_Class
Ack = BSLDLL.startBSL(MSComm1)
The ActiveX DLL and the application build without errors, but when I
run the application, I get the following error on the BSLDLL.startBSL
line
run-time error '424' object required
I saw some postings that indicated I should be able to do this, but I
am running out of ideas. Help would be greatly appreciated,
Stacy
J French - 29 Nov 2005 11:16 GMT
>I have a VB 6 application that uses the MSComm control to communicate
>with a BootStrap Loader on a TI Chip. I would like to create a DLL so
[quoted text clipped - 24 lines]
>
>run-time error '424' object required
I think I understand what you are up to
The MSCOM.CommID Property contains the Windows File Handle of an open
Comm port
- one can use the APIs to toggle CTS and DTR
- it might be simpler ...
BTW I don't think you should pass an Object ByVal
stacy@sensorswitch.com - 29 Nov 2005 13:22 GMT
Thanks for the help, I've read alot of posts about how to pass an
object, opinions differ. If you don't mind another question, What
API's can I use to toggle CTS and DTR? I find that the Windows
documentation makes finding the correct API very difficult if you don't
know it's name.
Stacy
J French - 29 Nov 2005 13:54 GMT
>Thanks for the help, I've read alot of posts about how to pass an
>object, opinions differ. If you don't mind another question, What
>API's can I use to toggle CTS and DTR? I find that the Windows
>documentation makes finding the correct API very difficult if you don't
>know it's name.
True
- it requires digging through the Win32 Programmer's Help File
Do you have that ?
If not : www.jerryfrench.co.uk/utils/win32sdk.zip
(it is old but very useful)
Here are some snippets from my COMM opus :-
Private Declare Function EscapeCommFunction Lib "kernel32" ( _
ByVal nCid As Long, _
ByVal nFunc As Long) As Long
Private Declare Function GetCommModemStatus Lib "kernel32" ( _
ByVal hFile As Long, _
lpModemStat As Long) As Long
Private Const MS_CTS_ON = &H10&
Private Const MS_DSR_ON = &H20&
Private Const MS_RING_ON = &H40&
Private Const MS_RLSD_ON = &H80&
Private Const CLRDTR = 6 ' Clears the DTR (data-terminal-ready)
signal.
Private Const CLRRTS = 4 ' Clears the RTS (request-to-send) signal.
Private Const SETDTR = 5 ' Sends the DTR (data-terminal-ready) signal.
Private Const SETRTS = 3 ' Sends the RTS (request-to-send) signal.
Public Sub DtrOn(Erm$)
Erm$ = ""
If EscapeCommFunction(cmn.hFile, SETDTR) = 0 Then
Erm$ = "Failed EscapeCommFunction() SETDTR"
End If
End Sub
Public Sub DtrOff(Erm$)
Erm$ = ""
If EscapeCommFunction(cmn.hFile, CLRDTR) = 0 Then
Erm$ = "Failed EscapeCommFunction() CLRDTR"
End If
End Sub
........
If GetCommModemStatus(cmn.hFile, Status) = 0 Then
Erm$ = "Failed GetCommModemStatus"
Exit Function
End If
' ---
If Status And MS_CTS_ON Then
LF_CTS_On = True
Exit Function
End If
TDC - 29 Nov 2005 21:36 GMT
>BTW I don't think you should pass an Object ByVal
I always pass object references ByVal, unless the object is a "return"
or "out" parameter.
Remember that ByVal does not copy or clone the object, it just makes a
4 byte copy of the object reference (or pointer).
In fact, I use ByVal on all datatypes except extremely large Strings
(and of course arrays and user-defined types).
My two cents,
Tom
J French - 30 Nov 2005 10:03 GMT
>>BTW I don't think you should pass an Object ByVal
>
[quoted text clipped - 3 lines]
>Remember that ByVal does not copy or clone the object, it just makes a
>4 byte copy of the object reference (or pointer).
Yes, I stand corrected
I suspect that creating another reference will bump up the reference
count, but that is no hardship
Steve Gerrard - 29 Nov 2005 15:23 GMT
> The ActiveX DLL and the application build without errors, but when I
> run the application, I get the following error on the BSLDLL.startBSL
> line
>
> run-time error '424' object required
Unless you are debugging with the source code of the DLL, the error occurring on
the BSLDLL.startBSL line may mean only that an error occurred somewhere in the
DLL.
Also, Jerry's note about not passing an object by value may be more relevant for
a control such as MSComm, since a control has to be on a form and be loaded,
etc., so it can't be passed by value as easily.