473,473 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

COM Objects

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
12 6403

"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

"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
"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
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

"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

"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
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

"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
| | 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
"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
| 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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dasod | last post by:
I would like to know if my method to remove list objects is correct in this small test program. It seems to me that there might be a simplier way, but I'm afraid I don't know enough about list...
9
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
3
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements -...
8
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
21
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not...
27
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.