Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
4.60/5 (2 votes)
See more:
I m trying to cast few lines of c# code into c++.
m having problem in using
private IntPtr m_hContext = IntPtr.Zero;
IntPtr hContext = Marshal.AllocHGlobal(Marshal.SizeOf(m_hContext));
m_hContext = Marshal.ReadIntPtr(hContext);

I m unabgle to find its equivalence in c++... Help me out..
Maciej Los 18-May-12 10:44am    
Take a look here: Void * To InPtr Conversion[^]
Anil Kumar 23 18-May-12 11:07am    
can u give me ny sample code for this???

Hi Hellexx,
maybe it will help you :
You can use the Demo Edition of C++ to C# Converter for folder conversions up to 2000 lines and code snippet conversions up to 200 lines at a time.
Share this answer
do you have tried GlobalAlloc() or GlobalHandle()?
Share this answer
Anil Kumar 23 18-May-12 11:18am    
na i have not ... r u sure it will work in c++
IntPtr can refer to a conventional pointer of C++, whatever it is : void*, int*, long*, float*, so on.

If you are gonna call a C++ function which returns a pointer or need a referenced pointer parameter,

you surely needs IntPtr in your C# code like you wrote.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900