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

I m unabgle to find its equivalence in c++... Help me out..
Posted
Comments
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???

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
 
Hi Hellexx,
maybe it will help you : http://tangiblesoftwaresolutions.com/Product_Details/CSharp_to_CPlusPlus_Converter_Details.html
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
 
Comments
Anil Kumar 23 18-May-12 11:18am    
na i have not ... r u sure it will work in c++

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