473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Passing string over DLL boundaries.

Hi all,

This a problem about windows dll.

I wrote a dll export this API to learn how strings are passed over the
dll boundaries.

extern "C" PINVOKELIB_API char * TestStringAsResult()
{
STRSAFE_LPWSTR result = (STRSAFE_LPWSTR)CoTaskMemAlloc( 1000 * 1000
* 100 );
StringCchCopy( result, 1000 , (STRSAFE_LPWSTR)"This is return
value" );
return (char *) result;
}

In my opinion, as the function allocated memory but do not release
it, any call of it would leak 100M bytes memory.

But that doesn't happen! Is there some mechanism that automatically
release memory of string passed over dll boundaries?

Thanks a lot!
Aug 24 '08 #1
4 2484
一首诗 wrote:
Hi all,

This a problem about windows dll.
Then you really should ask in a windows group, this isn't a C++ question.

--
Ian Collins.
Aug 24 '08 #2
一首诗 wrote:
extern "C" PINVOKELIB_API char * TestStringAsResult()
{
STRSAFE_LPWSTR result = (STRSAFE_LPWSTR)CoTaskMemAlloc( 1000 * 1000
* 100 );
StringCchCopy( result, 1000 , (STRSAFE_LPWSTR)"This is return
value" );
return (char *) result;
}

In my opinion, as the function allocated memory but do not release
it, any call of it would leak 100M bytes memory.

But that doesn't happen! Is there some mechanism that automatically
release memory of string passed over dll boundaries?
Without knowing what STRSAVE_LPWSTR does it's impossible to say.
However, that name itself may be telling us something.
Aug 24 '08 #3
Juha Nieminen wrote:
>
Without knowing what STRSAVE_LPWSTR does it's impossible to say.
However, that name itself may be telling us something.
That this isn't a C++ question?

--
Ian Collins.
Aug 24 '08 #4
Ian Collins wrote:
Juha Nieminen wrote:
> Without knowing what STRSAVE_LPWSTR does it's impossible to say.
However, that name itself may be telling us something.

That this isn't a C++ question?
It could be, if we knew what STRSAVE_LPWSTR is.
Aug 24 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
8
by: Drew | last post by:
I have recently converted all of my native C++ dll's to be compiled with the /CLR switch. After doing this, I notcied a very strange and frustrating issue. One of my managed dll's calls another...
6
by: Archana | last post by:
Hi, I want to forward a request as it is from an aspx page(could be a web service too) in one application to another aspx page in a different application. The intial request will be having...
2
by: sonaliagr | last post by:
I am trying to update a msg array in function by passing the address but it is showing an error. and also, i want the value of msg array to be accessible to the full code that is inside the main...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
20
by: Xcriber51 | last post by:
Hi -- I'm not entirely familiar with the norms and standard libraries of JavaScript so if the answer to this is yesterday's news, please ignore. I'm trying to write a simple text formatting...
5
by: Kenneth Porter | last post by:
How do I pass a container from C# to C++? My client is writing an app in C# that needs to pass a collection of 3- space vectors to my native C++ library. It will also need to read back the...
13
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.