473,320 Members | 1,991 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.

is Marshal::FreeHGlobal() possible?

Hi,

After converting String* to Char*, I need to call Marshal::FreeHGlobal().
Fine. But I need pass this Char* to an unmagaed C++ class and the managed C++
class is not possible to do Marshal::FreeHGlobal() any more. What should I
do? delete Char* in the unmanaged class?

Thanks
Nov 17 '05 #1
2 2229
Calling delete[] on the char array may do the trick, but if it was created
using StringToHGlobal*, it may be possible that other objects may have been
created that could only be deleted w/ a call to FreeHGlobal. I think you
should be good though, worst case scenario is you would have to perform yet
another copy of the char array returned by StringToHGlobal* using strcpy or
something similar.

"Fei Li" <Fe***@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Hi,

After converting String* to Char*, I need to call Marshal::FreeHGlobal().
Fine. But I need pass this Char* to an unmagaed C++ class and the managed
C++
class is not possible to do Marshal::FreeHGlobal() any more. What should I
do? delete Char* in the unmanaged class?

Thanks

Nov 17 '05 #2
Calling delete[] on the char array may do the trick, but if it was created
using StringToHGlobal*, it may be possible that other objects may have been
created that could only be deleted w/ a call to FreeHGlobal. I think you
should be good though, worst case scenario is you would have to perform yet
another copy of the char array returned by StringToHGlobal* using strcpy or
something similar.

"Fei Li" <Fe***@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Hi,

After converting String* to Char*, I need to call Marshal::FreeHGlobal().
Fine. But I need pass this Char* to an unmagaed C++ class and the managed
C++
class is not possible to do Marshal::FreeHGlobal() any more. What should I
do? delete Char* in the unmanaged class?

Thanks

Nov 17 '05 #3

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

Similar topics

0
by: Joerg M. Colberg | last post by:
Hi all, I got a weird problem when using FreeHGlobal. The error message I get is: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at...
0
by: Fei Li | last post by:
Hi, After converting String* to Char*, I need to call Marshal::FreeHGlobal(). Fine. But I need pass this Char* to an unmagaed C++ class and the managed C++ class is not possible to do...
13
by: Just Me | last post by:
The following almost works. The problem is Marshal.PtrToStringAuto seems to terminate at the first null so I don't get the full string. Any suggestions on how to fix this? Or how to improve the...
2
by: twawsico | last post by:
I have a piece of code that needs to read the contents of a binary file (that I've created with another app) into an array of structures. The binary data in the file represents just a series of...
1
by: Goran | last post by:
Hi all! I need to pass managed String from to C-style APIs. I see I can use Marshal::StringToXXX functions. Is this the best we have? I understand this will allocate a new string and create copy...
4
by: cleanrabbit | last post by:
Hello! I hate having to do this, because im almost certain there is someone in the world that has come across this problem and i just havent found their solution yet, so i do appologise if this...
0
by: Dilip | last post by:
I have cross-posted this question to 3 newsgroups since I am not sure exactly where it belongs (and some NG's have very less activity). Apologies in advance for this. I have set the followup to...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
2
by: O.B. | last post by:
I have operation within a class that marshals the data into a byte array. Below are three different ways that work. Are there any downsides to using one over the the other? public virtual byte...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
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.