473,414 Members | 1,609 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,414 software developers and data experts.

Problem with FreeHGlobal

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 System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32
errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.FreeHGlobal (IntPtr hglobal)

Here's the code:

// the variables lines and vertices are defined elseplace
IntPtr num_pointer = Marshal::AllocHGlobal(lines*sizeof(int));
IntPtr id_pointer = Marshal::AllocHGlobal(lines*sizeof(int));
IntPtr coord1_pointer = Marshal::AllocHGlobal(vertices*sizeof(double));
// some more of these
// num, id, and coord1 are passed to this code from some other code
Marshal::Copy((*num), 0, num_pointer, lines);
Marshal::Copy((*id), 0, id_pointer, lines);
Marshal::Copy((*coord1), 0, coord1_pointer, vertices);
// some more of these
int *pnum_pointer = (int *) (num_pointer.ToPointer());
int *pid_pointer = (int *) (id_pointer.ToPointer());
double *pcoord1_pointer = (double *) (coord1_pointer.ToPointer());
// some more of these
// some processing (calling unmanaged code...)
Marshal::FreeHGlobal(num_pointer);
Marshal::FreeHGlobal(id_pointer);
Marshal::FreeHGlobal(coord1_pointer);

The last lines give the FreeHGlobals that break. If I comment those
out, the code runs though fine. What am I doing wrong here?

Best,
Joerg Colberg

Nov 17 '05 #1
0 833

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

Similar topics

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...
2
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...
2
by: Travis | last post by:
I'm working on a project where we're building a .NET wrapper to IBM's MQ Workflow C++ API. My original intention was to wrap the Workflow API with a managed C++ assembly that in turn could be...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.