By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

COM Objects

P: n/a
Hello,
I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
Uncaught exception 'com_exception' wih message 'Failed to create COM
object 'MSComm32.OCX' : Incorrect syntax'

The OCX is present on the system and I could succesfully use it
through visual basic. Any clue ?

Regards,
Rémy

Apr 24 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a

"Rémy Sanchez" <th****@gmail.comwrote in message
news:11**********************@n35g2000prd.googlegr oups.com...
[Hello,
I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
Uncaught exception 'com_exception' wih message 'Failed to create COM
object 'MSComm32.OCX' : Incorrect syntax'

The OCX is present on the system and I could succesfully use it
through visual basic. Any clue ?
]
These OCX-es are meant to be used from Windows-Forms. Since PHP is a server
side technology, you should use other Serial Port libraries.
Success
--
Compatible ASP Session replacement for web farms
http://www.nieropwebconsult.nl/asp_s...manager.htminc

Apr 24 '07 #2

P: n/a

"Rémy Sanchez" <th****@gmail.comwrote in message
news:11**********************@n35g2000prd.googlegr oups.com...
Hello,
I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
Uncaught exception 'com_exception' wih message 'Failed to create COM
object 'MSComm32.OCX' : Incorrect syntax'

The OCX is present on the system and I could succesfully use it
through visual basic. Any clue ?

==============

what does your code look like?

oh, just noticed...you're using an ocx. you need to use a dll. ocx's require
containers for instanciation...i.e. a window. i don't think you can call
window api's directly from php in order to create a window and then
co-create the ocx for that window.

if you aren't doing anything dramatic with your port communications, you can
just use php's built-in file i/o. iirc, your path would be:

'//COM1' (or whatever port you were wanting to use).

if you still want/need the ocx, you can create a dll that contains a
form...just plop the ocx on the form and wrap it's interfaces publically.
then COM that from php.

hth,

me
Apr 24 '07 #3

P: n/a
"Rémy Sanchez" <th****@gmail.comwrote in message
news:11**********************@n35g2000prd.googlegr oups.com...
Hello,
I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
Uncaught exception 'com_exception' wih message 'Failed to create COM
object 'MSComm32.OCX' : Incorrect syntax'

The OCX is present on the system and I could succesfully use it
through visual basic. Any clue ?

Regards,
Rémy
The interfaces are not something php would understand. However, it would be
quite possible to wrap them within a c/c++ dll. Not too hard to do if you
use ATL and know a little about com interfaces, and then map and call via
the dll's interfaces. Visual basic is com so the complexity is hidden from
you
Apr 25 '07 #4

P: n/a
I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
Uncaught exception 'com_exception' wih message 'Failed to create COM
object 'MSComm32.OCX' : Incorrect syntax'

The OCX is present on the system and I could succesfully use it
through visual basic. Any clue ?
How do you use it? COM objects must be registered on the system and
called with the name given in the registry (HKEY_classes_root).

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Apr 25 '07 #5

P: n/a

"Vince Morgan" <vi****@REMOVEoptusnet.com.auwrote in message
news:46***********************@news.optusnet.com.a u...
| "Rémy Sanchez" <th****@gmail.comwrote in message
| news:11**********************@n35g2000prd.googlegr oups.com...
| Hello,
| I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
| Uncaught exception 'com_exception' wih message 'Failed to create COM
| object 'MSComm32.OCX' : Incorrect syntax'
|
| The OCX is present on the system and I could succesfully use it
| through visual basic. Any clue ?
|
| Regards,
| Rémy
| The interfaces are not something php would understand.

actually, the interfaces are com...so php can understand them.

| However, it would be
| quite possible to wrap them within a c/c++ dll.

first, he's using mscom32.ocx. that means he's still developing in vb
classic...errr... vb < .net. there are very few in that genre that have ever
delved into c/c++. otherwise, he'd be able to create a com port controller
dll in about .5 hours. :)

| Not too hard to do if you
| use ATL and know a little about com interfaces, and then map and call via
| the dll's interfaces.

i doubt he's heard of atl's or any other kind of template library. i can
hear the 'huh?' from here.

| Visual basic is com so the complexity is hidden from you

since it does abide by the com contract, all he'd have to do for a wrapper
would be to create a form, drop the control on it, then expose it's
interfaces publically, and compile his new dll. php can consume the
interfaces from there.
Apr 25 '07 #6

P: n/a

"Steve" <no****@example.comwrote in message
news:AF*****************@newsfe04.lga...
|
| "Rémy Sanchez" <th****@gmail.comwrote in message
| news:11**********************@n35g2000prd.googlegr oups.com...
| Hello,
| I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
| Uncaught exception 'com_exception' wih message 'Failed to create COM
| object 'MSComm32.OCX' : Incorrect syntax'
|
| The OCX is present on the system and I could succesfully use it
| through visual basic. Any clue ?
|
| ==============
|
| what does your code look like?
|
| oh, just noticed...you're using an ocx. you need to use a dll. ocx's
require
| containers for instanciation...i.e. a window. i don't think you can call
| window api's directly from php in order to create a window and then
| co-create the ocx for that window.
|
| if you aren't doing anything dramatic with your port communications, you
can
| just use php's built-in file i/o. iirc, your path would be:
|
| '//COM1' (or whatever port you were wanting to use).

brrrrr!!!

there are two 'correct' path nomanclatures. first:

'COM1'

however on windows, this will only allow you to communicate with up to 8 com
ports. this:

'\\.\COM1'

removes the limitation. i found some code i'd written some time back where i
thought i'd done some com port work. that's what i've gotten so far. i think
i built a com port dll with vb once...which is what i'm looking for now.

the great thing about archiving some of your previous work is that you'll
always have it to go back to. the bad thing is that it gets pretty large
after so many years. :)
Apr 25 '07 #7

P: n/a
this code will allow you to enum all the com ports on your windows machine
(fix the text-wrapping):

=============

Option Explicit

'================================================= ===============================================
Private Const mcstrRegKeyPorts As String * 29 =
"HARDWARE\DEVICEMAP\SERIALCOMM"
'================================================= ===============================================
Public Const CB_FINDSTRINGEXACT As Long = &H158
Public Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
Public Const HKEY_LOCAL_MACHINE As Long = &H80000002
Public Const KEY_QUERY_VALUE As Long = &H1
Public Const MAX_PATH As Long = 255
Public Const REG_SZ As Long = 1
'================================================= ===============================================
Public Declare Sub Copy Lib "kernel32.dll" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal lngHKey As
Long) As Long
Public Declare Function RegEnumValue Lib "advapi32.dll" Alias
"RegEnumValueA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal
lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long,
lpType As Long, lpData As Byte, lpcbData As Long) As Long
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias
"RegOpenKeyExA" (ByVal lngHKey As Long, ByVal lpSubKey As String, ByVal
ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Declare Function ShowComSettings Lib "winspool.drv" Alias
"ConfigurePortA" (ByVal pName As String, ByVal hWnd As Long, ByVal pPortName
As String) As Long
'================================================= ===============================================

Public Function ComPorts() As String()
Dim lngHKey As Long
Dim lngPtr As Long
Dim lngReturn As Long
Dim strKeyName As String
Dim lngKeyLen As Long
Dim bytKeyValue(0 To 254) As Byte
Dim lngKeyValueLen As Long
Dim lngDataType As Long
Dim strValue As String
Dim strDefinedPorts() As String
lngReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE, mcstrRegKeyPorts, 0,
KEY_QUERY_VALUE, lngHKey)
If lngReturn <0 Then Exit Function
While lngReturn = 0
strKeyName = Space(MAX_PATH)
lngKeyLen = Len(strKeyName)
lngKeyValueLen = lngKeyLen
lngReturn = RegEnumValue(lngHKey, _
lngPtr, _
strKeyName, _
lngKeyLen, _
0&, _
lngDataType, _
bytKeyValue(0), _
lngKeyValueLen)
If lngReturn = 0 Then
strKeyName = Left$(strKeyName, lngKeyLen)
lngKeyValueLen = lngKeyValueLen - 1
strValue = Space(lngKeyValueLen)
Copy ByVal strValue, bytKeyValue(0), lngKeyValueLen
ReDim Preserve strDefinedPorts(lngPtr)
strDefinedPorts(lngPtr) = strValue
lngPtr = lngPtr + 1
End If
Wend
RegCloseKey lngHKey
Sort strDefinedPorts, LBound(strDefinedPorts), UBound(strDefinedPorts)
ComPorts = strDefinedPorts
End Function

Private Function Sort(ByRef strArray() As String, intStartPtr As Integer,
intEndPtr As Integer)
Dim intLow As Integer
Dim intHigh As Integer
Dim strElement As String
intLow = intStartPtr
intHigh = intEndPtr
strElement = strArray((intStartPtr + intEndPtr) / 2)
While (intLow <= intHigh)
While (strArray(intLow) < strElement And intLow < intEndPtr)
intLow = intLow + 1
Wend
While (strElement < strArray(intHigh) And intHigh intStartPtr)
intHigh = intHigh - 1
Wend
If (intLow <= intHigh) Then
strElement = strArray(intLow)
strArray(intLow) = strArray(intHigh)
strArray(intHigh) = strElement
intLow = intLow + 1
intHigh = intHigh - intHigh
End If
Wend
If (intStartPtr < intHigh) Then Sort strArray, intStartPtr, intHigh
If (intLow < intEndPtr) Then Sort strArray, intLow, intEndPtr
End Function
Apr 25 '07 #8

P: n/a

"Steve" <no****@example.comwrote in message
news:uk***********@newsfe04.lga...
>
"Vince Morgan" <vi****@REMOVEoptusnet.com.auwrote in message
news:46***********************@news.optusnet.com.a u...
| "Rémy Sanchez" <th****@gmail.comwrote in message
| news:11**********************@n35g2000prd.googlegr oups.com...
| Hello,
| I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
| Uncaught exception 'com_exception' wih message 'Failed to create COM
| object 'MSComm32.OCX' : Incorrect syntax'
|
| The OCX is present on the system and I could succesfully use it
| through visual basic. Any clue ?
|
| Regards,
| Rémy
| The interfaces are not something php would understand.

actually, the interfaces are com...so php can understand them.
Hmmm!!! that's very interesting :)
I had no idea whatsoever. Must look into that further.
>
| However, it would be
| quite possible to wrap them within a c/c++ dll.

first, he's using mscom32.ocx. that means he's still developing in vb
classic...errr... vb < .net. there are very few in that genre that have
ever
delved into c/c++. otherwise, he'd be able to create a com port controller
dll in about .5 hours. :)

| Not too hard to do if you
| use ATL and know a little about com interfaces, and then map and call
via
| the dll's interfaces.

i doubt he's heard of atl's or any other kind of template library. i can
hear the 'huh?' from here.
Yes, that is hardly helpful now that you mention it.
>
| Visual basic is com so the complexity is hidden from you

since it does abide by the com contract, all he'd have to do for a wrapper
would be to create a form, drop the control on it, then expose it's
interfaces publically, and compile his new dll. php can consume the
interfaces from there.
A form?? That did confuse me when I read it. Where would I look into this
Steve?
Vince

Apr 25 '07 #9

P: n/a
| | The interfaces are not something php would understand.
| >
| actually, the interfaces are com...so php can understand them.
|
| Hmmm!!! that's very interesting :)
| I had no idea whatsoever. Must look into that further.

just depends on how you compile it (exe, dll, ocx, etc.)

| i doubt he's heard of atl's or any other kind of template library. i can
| hear the 'huh?' from here.
|
| Yes, that is hardly helpful now that you mention it.

no, it's good advice. if the op isn't lazy and can google, there are free
tools on the net that will build atl's for you without you even having
development software installed on your machine. that would probably work
just fine.

| | Visual basic is com so the complexity is hidden from you
| >
| since it does abide by the com contract, all he'd have to do for a
wrapper
| would be to create a form, drop the control on it, then expose it's
| interfaces publically, and compile his new dll. php can consume the
| interfaces from there.
| A form?? That did confuse me when I read it. Where would I look into
this
| Steve?

i'm not sure i know of a resource anymore. i think mvps.org is still out
there.

anyway, all you have to do is create a project with a public class object, a
form with the control on it, implement the mscomm control's interfaces
(literally, using 'implements')...when someone creates an instance of your
class, your class loads the form. when they call a method or set/get a
property of your class, you call/set/get the control's corresponding one.

say your form is form1 and it's com control is mscomm1. your class would do:

======================

'this is your com control var

private comControl as mscomcontrol ' i can't remember how it shows
' when the project has a ref to it
' but you get the idea

'interface declaration

implements mscomcontrol

'set the control var to the control instance
'this is in the class' initialize()

set comControl = form1.mscomm1

'this is after the class initializes
'and someone calls open()

public function open(byval strSettings as string) implements
mscomcontrol.open
comControl.open(strSettings)
end function

====================

that's all pseudo-code, but it's pretty close to the real-deal. if you
compile this as a dll, life is good and the problem is solved.

cheers.
Apr 25 '07 #10

P: n/a
"Steve" <no****@example.comwrote in message
news:hk***************@newsfe12.lga...
| | The interfaces are not something php would understand.

'this is your com control var

private comControl as mscomcontrol ' i can't remember how it shows
' when the project has a ref to it
' but you get the idea

'interface declaration

implements mscomcontrol

'set the control var to the control instance
'this is in the class' initialize()

set comControl = form1.mscomm1

'this is after the class initializes
'and someone calls open()

public function open(byval strSettings as string) implements
mscomcontrol.open
comControl.open(strSettings)
end function

====================

that's all pseudo-code, but it's pretty close to the real-deal. if you
compile this as a dll, life is good and the problem is solved.

cheers.
Looks very much like an activex exe, or activex document exe Steve, in fact
the later includes the form by default.
Thanks for that.
The OP may be able to work this out if he is familiar with say VB6.
Vince
Apr 25 '07 #11

P: n/a
| Looks very much like an activex exe, or activex document exe Steve, in
fact
| the later includes the form by default.
| Thanks for that.

that's because the same code works works *any* way you compile it. however
for use in php, he'll need to compile the project as a standard dll (which
he'll need to register on his server if he just copies over...installing it
will do that for him if he goes that route...regsvr32 -i componentName).

| The OP may be able to work this out if he is familiar with say VB6.

i assumed vb6 (or previous) because he uses the control. if .net, there's
already a serial port namespace he can use to create a com dll (depreciated
now as com is :)

but again, why do *any* of this if all he's going to do is write some data
to the port with no intention of signalling? he can just use file i/o
directly from php from that. same thing goes for vb. in fact...

i asked one of my vb developers one time why he had just spent the past 8
hours developing a label printing application where 7 of those hours were
spent getting the data to the printer - which was connected via a serial
port. he had written some beautiful port communication routines that would
have made dick greer feel inferior. :) it was all one way communication
though - and always would be. so, i bet him i could do all of that in 3
lines of code...he laughed until i wrote:

Open strComPort For Output As #lngFile
Write #lngFile, strLabel
Close #lngFile

or something similar at the time. the free dinner was great. :)
Apr 25 '07 #12

P: n/a
"Steve" <no****@example.comwrote in message
news:GO**************@newsfe02.lga...
LOL
Yep, could have even used qbasic, and virtualy the same code with the same
result. ;)
Apr 25 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.