Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Passing interface pointer from Delphi to .NET through method parameter


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Feb 7, 2018 10:25 AM Last Post By: Murthy Vinjamuri
Murthy Vinjamuri

Posts: 3
Registered: 2/27/18
Passing interface pointer from Delphi to .NET through method parameter  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 9:16 AM
My application has some legacy code where the Delphi application passing interface pointer (for the purpose of calling callback methods) to COM application. This code has been working fine.
I'm changing COM application to .NET application. The same method call of passing interface pointer from Delphi to .NET fails with access violation on Delphi side.
Can we pass pointers between Delphi and .NET (Delphi is unmanaged and .NET is managed). Do I need to do anything extra to make this mechanism work? Please let me know your thoughts.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Passing interface pointer from Delphi to .NET through method parameter  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 9:29 AM   in response to: Murthy Vinjamuri in response to: Murthy Vinjamuri
Murthy Vinjamuri wrote:

I'm changing COM application to .NET application. The same method call
of passing interface pointer from Delphi to .NET fails with access
violation on Delphi side.

Please show the actual code on both sides.

Can we pass pointers between Delphi and .NET (Delphi is unmanaged and
.NET is managed).

Of course you can, .NET supports COM interfaces.

--
Remy Lebeau (TeamB)
Murthy Vinjamuri

Posts: 3
Registered: 2/27/18
Re: Passing interface pointer from Delphi to .NET through method parameter  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 9:35 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for your prompt reply.

The method declaration in .NET is shown below.

public void RegisterCallback(ICxEFEMCB pCB)
{

}

ICxEFEMCB is an interface implemented by Delphi class. Delphi code is shown below. The method RegisterCallback() throws Access Violation error.

if (ComWrapper <> nil) AND (ComWrapper.GetCimEFEM <> nil) then
ComWrapper.GetCimEFEM.RegisterCallback(self as ICxEFEMCB);

I'm able to call other methods with integer parameter without any issue. I have this issue with only passing pointers. Please let me know if you have any thoughts.

Remy Lebeau (TeamB) wrote:
Murthy Vinjamuri wrote:

I'm changing COM application to .NET application. The same method call
of passing interface pointer from Delphi to .NET fails with access
violation on Delphi side.

Please show the actual code on both sides.

Can we pass pointers between Delphi and .NET (Delphi is unmanaged and
.NET is managed).

Of course you can, .NET supports COM interfaces.

--
Remy Lebeau (TeamB)

Edited by: Murthy Vinjamuri on Feb 7, 2018 9:37 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Passing interface pointer from Delphi to .NET through method parameter [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 10:23 AM   in response to: Murthy Vinjamuri in response to: Murthy Vinjamuri
Murthy Vinjamuri wrote:

The method declaration in .NET is shown below.

public void RegisterCallback(ICxEFEMCB pCB)
{

}

And how is it being declared on the Delphi side? How is Delphi
accessing RegisterCallback()? Is it exported as a DLL function? COM
interop?

ICxEFEMCB is an interface implemented by Delphi class.

And how is ICxEFEMCB declared on the .NET side? On the Delphi side?

Delphi code is shown below. The method RegisterCallback() throws
Access Violation error.

if (ComWrapper <> nil) AND (ComWrapper.GetCimEFEM <> nil) then
ComWrapper.GetCimEFEM.RegisterCallback(self as ICxEFEMCB);

What is ComWrapper? What is GetCimEFEM? How are they initialized?
What is Self pointing at?

How do you expect people to help you if you don't SHOW everything you
are using?

--
Remy Lebeau (TeamB)
Murthy Vinjamuri

Posts: 3
Registered: 2/27/18
Re: Passing interface pointer from Delphi to .NET through method parameter [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 10:25 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I'm creating a sample to demonstrate the issue. Will post the sample after I'm done.

Remy Lebeau (TeamB) wrote:

Murthy Vinjamuri wrote:

The method declaration in .NET is shown below.

public void RegisterCallback(ICxEFEMCB pCB)
{

}

And how is it being declared on the Delphi side? How is Delphi
accessing RegisterCallback()? Is it exported as a DLL function? COM
interop?

ICxEFEMCB is an interface implemented by Delphi class.

And how is ICxEFEMCB declared on the .NET side? On the Delphi side?

Delphi code is shown below. The method RegisterCallback() throws
Access Violation error.

if (ComWrapper <> nil) AND (ComWrapper.GetCimEFEM <> nil) then
ComWrapper.GetCimEFEM.RegisterCallback(self as ICxEFEMCB);

What is ComWrapper? What is GetCimEFEM? How are they initialized?
What is Self pointing at?

How do you expect people to help you if you don't SHOW everything you
are using?

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02