 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jim Sawyer Guest
|
Posted: Sun Jul 18, 2004 5:35 pm Post subject: Using a C++ Com Object with Delphi |
|
|
Using Delphi 7. Have a C++ DLL (com object). A function
SendMessage
is defined in the C++ header file as
STDMETHOD (SendMessage)(VARIANT * psa_Data, SND_STATUS *pVal);
I know that I need to pass an "array of byte" to this function.
Specifically I need
to pass the array
aPortInquiryResponse
which is
aPortInquiryResponse[ 0 ] := 83;
aPortInquiryResponse[ 1 ] := 77;
aPortInquiryResponse[ 2 ] := 32;
aPortInquiryResponse[ 3 ] := 49;
aPortInquiryResponse[ 4 ] := 32;
aPortInquiryResponse[ 5 ] := 115;
to SendMessage. When I try
IDXVetLab.SendMessage( aPortInquiryResponse )
I get the error message
[Error] IDXTest1.pas(249): Types of actual and formal var parameters
must be identical
I don't know C++. Can anyone tell me what I am doing wrong?
Thank you.
Jim Sawyer
|
|
| Back to top |
|
 |
Jim Sawyer Guest
|
Posted: Mon Jul 19, 2004 3:33 pm Post subject: Re: Using a C++ Com Object with Delphi |
|
|
Leon -
I'm trying the following (I'm just including the necessary parts of the
code):
type
aByteArray = Array of byte;
pByteArray = ^aByteArray;
procedure TVetLabForm.VetLabPacketQueued(Sender: TObject);
var
pPortInquiryResponse: pByteArray;
begin
......
pPortInquiryResponse^[ 0 ] := 83;
pPortInquiryResponse^[ 1 ] := 77;
pPortInquiryResponse^[ 2 ] := 32;
pPortInquiryResponse^[ 3 ] := 49;
pPortInquiryResponse^[ 4 ] := 32;
pPortInquiryResponse^[ 5 ] := 115;
VetLab.SendMessage( pPortInquiryResponse );
.......
end;
I still get the error message
[Error] IDXTest1.pas(249): Types of actual and formal var parameters
must be identical
Incidently, the second parameter of the C++ function is it's return value
(which also must be a pointer), but I'm not worried about that yet.
Any suggestions???
Thank you,
Jim Sawyer
"Leon Zandman" <NOSPAMusenet (AT) wirwar (DOT) com> wrote
| Quote: | Hi Jim,
is defined in the C++ header file as
STDMETHOD (SendMessage)(VARIANT * psa_Data, SND_STATUS *pVal);
I know that I need to pass an "array of byte" to this function.
You can't pass an "array of bytes" to that SendMessage function, because
it only accepts pointers. That's what the asterisk character (*) means.
So the first parameter is a pointer to a VARIANT and the second
parameter is a pointer to a SND_STATUS type.
When I try
IDXVetLab.SendMessage( aPortInquiryResponse )
Well, the first thing that's wrong is that you supplied one parameter
where there should be two (see above). The second thing is that it
should be a pointer to the data, not the actual data itself. So the
following would come closer:
IDXVetLab.SendMessage(@aPortInquiryResponse);
Greetz,
Leon
|
|
|
| Back to top |
|
 |
Jim Sawyer Guest
|
Posted: Tue Jul 20, 2004 8:16 pm Post subject: Re: Using a C++ Com Object with Delphi |
|
|
| Quote: | What does the Delphi IDE say when you press CTRL-SHIFT-SPACE while
inside the brackets. It should tell you the count and type of the
parameters.
|
CTRL+SHIFT+SPACE displays the following:
var Data: OleVariant
| Quote: |
type
vTest: VARIANT;
pTest: ^VARIANT;
|
Do you mean for these two declarations to by types? If so shouldn't they
have "=" signs between them? Do I still have a variable declared such as
var
aByteArray: Array[0..5] of byte;
with which to stuff the values
aByteArray[ 0 ] := 83;
aByteArray[ 1 ] := 77;
aByteArray[ 2 ] := 32;
aByteArray[ 3 ] := 49;
aByteArray[ 4 ] := 32;
aByteArray[ 5 ] := 115;
Then where do the vTest and pTest types come in? How do I use them to
provide the
var Data: OleVariant
argument to the function
VetLab.SendMessage( ?????? );
Also, does this indicate if one or two parameters are needed? I'm still
lost as Hogan's goat!!!
| Quote: | You are still not using two parameters. Unless the function makes use of
a default parameter, you must supply the second one...
Incidently, the second parameter of the C++ function is it's return
value
(which also must be a pointer), but I'm not worried about that yet.
Even if it is used as a return value, so still must specify it.
Greetz,
Leon
|
|
|
| Back to top |
|
 |
Jim Sawyer Guest
|
Posted: Tue Jul 20, 2004 10:15 pm Post subject: Re: Using a C++ Com Object with Delphi |
|
|
That both compiled and executed! I'm sending a port inquiry
response back to a com port. Com ports are always a mess.
So far it's not honoring my response, but that may be
because I'm not sending it what it needs to see. But,
thanks to you again, I'm one major step closer, getting
it to execute the function.
Thanks,
Jim Sawyer
PS - I'm only using one parameter... Also, I had to sign
a nondisclosure agreement in order to use the DLL which
is needed for me to add the capability to interface with
IDEXX blood chemistry lab equipment to my
veterinary management application. I called to see
if I could provide the DLL to you, but they are
already gone for the day. I suspect, however, that they
would balk. I will, however, inquire when I speak with
them again.
"Leon Zandman" <NOSPAMusenet (AT) wirwar (DOT) com> wrote
| Quote: | Also, does this indicate if one or two parameters are needed? I'm
still
lost as Hogan's goat!!!
I need some more information. Maybe you can send me the DLL?
Anyway, this next example compiles:
procedure TForm1.Button1Click(Sender: TObject);
var
a: array of byte;
v: OleVariant;
begin
SetLength(a,2);
a[0] := 12;
a[1] := 34;
v := a;
Maybe this helps?
Greetz,
Leon
|
|
|
| Back to top |
|
 |
Jim Sawyer Guest
|
Posted: Fri Jul 23, 2004 2:21 pm Post subject: Re: Using a C++ Com Object with Delphi |
|
|
Leon -
Thanks again! It's working beautifully!
Jim Sawyer
"Jim Sawyer" <nospam (AT) myaddress (DOT) info> wrote
| Quote: | That both compiled and executed! I'm sending a port inquiry
response back to a com port. Com ports are always a mess.
So far it's not honoring my response, but that may be
because I'm not sending it what it needs to see. But,
thanks to you again, I'm one major step closer, getting
it to execute the function.
Thanks,
Jim Sawyer
PS - I'm only using one parameter... Also, I had to sign
a nondisclosure agreement in order to use the DLL which
is needed for me to add the capability to interface with
IDEXX blood chemistry lab equipment to my
veterinary management application. I called to see
if I could provide the DLL to you, but they are
already gone for the day. I suspect, however, that they
would balk. I will, however, inquire when I speak with
them again.
"Leon Zandman" <NOSPAMusenet (AT) wirwar (DOT) com> wrote in message
news:cdk2qq$rr5$1 (AT) news3 (DOT) tilbu1.nb.home.nl...
Also, does this indicate if one or two parameters are needed? I'm
still
lost as Hogan's goat!!!
I need some more information. Maybe you can send me the DLL?
Anyway, this next example compiles:
procedure TForm1.Button1Click(Sender: TObject);
var
a: array of byte;
v: OleVariant;
begin
SetLength(a,2);
a[0] := 12;
a[1] := 34;
v := a;
Maybe this helps?
Greetz,
Leon
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|