🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by Old Wolf Wed, 08 Aug 2007 22:20
Compatibility with .NET
#1464
Author: Old Wolf
Date: Wed, 08 Aug 2007 22:20
9 lines
1033 bytes
I want to write a function using C++Builder2006, that
can be called from a third party .NET application.
The function accepts two ascii strings as input,
and returns an ascii string.

What are the requirements for this? My first guess
would be a COM DLL and the function takes
(BSTR*, BSTR, BSTR). 
Re: Compatibility with .NET
#1465
Author: Remy Lebeau (TeamB)
Date: Thu, 09 Aug 2007 01:33
13 lines
1207 bytes
"Old Wolf" <oldwolf@inspire.net.nz> wrote in message
news:46ba41a9@newsgroups.borland.com...

> I want to write a function using C++Builder2006,
> that can be called from a third party .NET application.

The only way to do that is to either write a COM object that .NET can load,
or export the function as a C-style function from a DLL that .NET can use
PInvoke to call.


Gambit
Re: Compatibility with .NET
#1466
Author: Old Wolf
Date: Thu, 09 Aug 2007 02:33
14 lines
1486 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>"Old Wolf" <oldwolf@inspire.net.nz> wrote:
>
>> I want to write a function using C++Builder2006,
>> that can be called from a third party .NET application.
>
>The only way to do that is to either write a COM object that .NET
>can load, or export the function as a C-style function from a DLL
>that .NET can use PInvoke to call.

If I go with the latter, then how does memory management
work? My function needs to return a string of characters
to the caller, how should this memory be allocated and freed?
Re: Compatibility with .NET
#1467
Author: David M
Date: Thu, 09 Aug 2007 02:41
18 lines
1643 bytes
> If I go with the latter, then how does memory management
> work? My function needs to return a string of characters
> to the caller, how should this memory be allocated and freed?

Often this is solved by having two methods or being able to call the one 
method twice - the first call calculates how much memory is needed and the 
second uses it.  That way the caller can allocate memory themselves and pass 
the pointer in.

I don't know how this works for .net calling a DLL though, presumably you 
can manually allocate and free memory in unsafe code in .net?

Another option would be to have your DLL return a handle it can then use 
later to free the memory when the caller requests it.

Cheers,

David
Re: Compatibility with .NET
#1468
Author: Remy Lebeau (TeamB)
Date: Thu, 09 Aug 2007 03:00
12 lines
1228 bytes
"David M" <vintagedave@gmail.com> wrote in message
news:46ba7ed5$1@newsgroups.borland.com...

> I don't know how this works for .net calling a DLL though,
> presumably you can manually allocate and free memory in
> unsafe code in .net?

.NET uses PInvoke to execute unmanaged DLL calls.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads