Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VC++ ActiveX in Delphi 6

Status
Not open for further replies.

mecva

Programmer
Feb 3, 2004
3
BR
Hi,

I've developed an ActiveX in Visual C++ and I'm trying to use it in Delphi. When I have a return of a method in VC++ it doesn't work well in Delphi. For example, if the return is a boolean value, it always returns true in Delphi despite of the value I return in C++ (true or false). Another example, if I return a smallint (short in VC++) I always get the value 21 in Delphi, despite of the value in C++. I have a piece of code to exemplify the situation:

Piece of code using the ActiveX in Delphi:

procedure TForm1.FormatMemoryClick(Sender: TObject);
var
result1 : Integer;
result2 : Smallint;
begin
result1 := SonetoToolkit1.TestMethod(4, result2);
ShowMessage('Result1: ' + IntToStr(result1) + ' Result2: ' + IntToStr(result2));
end;

Piece of code of the ActiveX made in VC++:

short CSonetoToolkitCtrl::TestMethod(short testParam, short FAR* testReturn)
{
*testReturn = testParam + 3;
short a = testParam + 5;
CString msg;
msg.Format("In C++\ntestParam: %d\ntestReturn: %d\nretorn: %d", testParam, *testReturn, a);
AfxMessageBox(msg);

return a;
}

Results:
- Message Box in VC++
"In C++
testParam: 4
testReturn: 7
return: 9"
- Message Box in Delphi
"Result1: 21 Result2: 7"

Then, the returned value 9 in VC++ was turned to 21 in Delphi. If I change the input param (4 in this case) to 1, 2, 3, 5 or 6, for example, the returned value in Delphi is always 21 instead of 6, 7, 8, 10 or 11.

If anyone has the solution of this problem I will be very thankful.

Márcio Azevedo.
 
Hi,

I found the solution of the problem.
When I import the ActiveX, Delphi creates the file <ActiveX name>TLB_Lib.pas inside the directory C:\Program Files\Borland\Delphi6\Imports. Taking a look inside the code I saw that each ActiveX interface method has a call to DefaultInterface.MethodName but the generated code has no &quot;Result :=&quot; before interface called method. I've changed the generated .pas file fixing this error and now it works well.

Thanks a lot for any try,

Márcio Azevedo.
 
I think it's a Delphi 6 problem or one of its builds. In Delphi 7 this error doesn't occur.

Márcio Azevedo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top