Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Accessing Borland C++ created DLLs from C#



Permlink Replies: 2 - Last Post: Dec 13, 2017 2:13 AM Last Post By: Andy Stobirski Threads: [ Previous | Next ]
Andy Stobirski

Posts: 18
Registered: 6/12/16
Accessing Borland C++ created DLLs from C#
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2017 3:01 AM
Hi there

I have a DLL containing a bunch of functions written using in C++ using Borland C++ Builder v5.0, the code is written in C++ and Delphi. Is it possible to use this DLL is C#?

Obviously, I could rewrite the stuff I need, but that would be rather time consuming, and would be a last resort.

Cheers

Andy
Remy Lebeau (Te...


Posts: 8,950
Registered: 12/23/01
Re: Accessing Borland C++ created DLLs from C#
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2017 9:55 AM   in response to: Andy Stobirski in response to: Andy Stobirski
Andy Stobirski wrote:

I have a DLL containing a bunch of functions written using in C++
using Borland C++ Builder v5.0, the code is written in C++ and
Delphi. Is it possible to use this DLL is C#?

It depends on what the signatures of the exported DLL functions look
like. If they are written to follow C semantics, and only use basic
interop-safe data types, then yes, you can use it in C# via PInvoke.
Otherwise, no.

--
Remy Lebeau (TeamB)
Andy Stobirski

Posts: 18
Registered: 6/12/16
Re: Accessing Borland C++ created DLLs from C#
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2017 2:01 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
It depends on what the signatures of the exported DLL functions look
like. If they are written to follow C semantics, and only use basic
interop-safe data types, then yes, you can use it in C# via PInvoke.
Otherwise, no.

--
Remy Lebeau (TeamB)

Thanks for your reply. After spending a lot of time stumbling by not specifying the CallingConvention, I was successful.

        [DllImport(@"DLLAmEncBorland.dll", CallingConvention = CallingConvention.Cdecl)]
        private unsafe static extern int* _encrypt(int[] pByteArray, int pLength);


Edited by: Andy Stobirski on Dec 13, 2017 2:12 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02