473,791 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IntPtr - what is this!?!?

Hello,

I come from C++ and i now have to work with C#, and someone tell me that
bye bye pointers but i think this is not true, i must convert a DIB image in
something that i can use in C# (like Image or Bitmap) and the only thing i
can do is a DIB into a IntPtr (a pointer). I do this with the platform
invoke method of Win32:

[DllImport("gdip lus.dll", ExactSpelling=t rue)]
internal static extern int GdipCreateBitma pFromGdiDib( IntPtr bminfo,
IntPtr pixdat, ref IntPtr image );

Now my little impression of what i do of it it's that the IntPtr is a
pointer to a Image!?!? right??!

If is, then how i do the cast (like in old good C++):
Image* pImg = (Image*) IntPtr_variable ;

Thanks
Nuno
Nov 15 '05 #1
2 31315
Hi Nuno,

From MSDN:

A platform-specific type that is used to represent a pointer or a handle.
The IntPtr type is designed to be an integer whose size is
platform-specific. That is, an instance of this type is expected to be
32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit
hardware and operating systems.

The IntPtr type can be used by languages that support pointers, and as a
common means of referring to data between languages that do and do not
support pointers.

IntPtr objects can also be used to hold handles. For example, instances of
IntPtr are used extensively in the System.IO.FileS tream class to hold file
handles.

The IntPtr type is CLS-compliant, while the UIntPtr type is not. Only the
IntPtr type is used in the common language runtime. The UIntPtr type is
provided mostly to maintain architectural symmetry with the IntPtr type.

It's normally used when you are calling to non managed code ( API, COM,
etc )

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Esculcas" <ne*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hello,

I come from C++ and i now have to work with C#, and someone tell me that bye bye pointers but i think this is not true, i must convert a DIB image in something that i can use in C# (like Image or Bitmap) and the only thing i
can do is a DIB into a IntPtr (a pointer). I do this with the platform
invoke method of Win32:

[DllImport("gdip lus.dll", ExactSpelling=t rue)]
internal static extern int GdipCreateBitma pFromGdiDib( IntPtr bminfo,
IntPtr pixdat, ref IntPtr image );

Now my little impression of what i do of it it's that the IntPtr is a
pointer to a Image!?!? right??!

If is, then how i do the cast (like in old good C++):
Image* pImg = (Image*) IntPtr_variable ;

Thanks
Nuno

Nov 15 '05 #2

Adding a little more details to this, GdipCreateBitma pFromGdiDib is going
to return a pointer to the native gdiplus Image object. You cannot cast
that to the managed Image object (the Common Language Runtime knows how to
handle managed objects, but doesn't understand native objects).

You should look at the System.Drawing namespace for methods that do what
you want. In particular, there is a Bitmap constructor that takes a
pointer to the bits as argument:

public Bitmap(
int width,
int height,
int stride,
PixelFormat format,
IntPtr scan0
);

If your bitmap is stored in a file or as a resource, there are even simpler
constructors you could use.

Good luck!

-- Ori.

--------------------
From: "Ignacio Machin" <ignacio.mach in AT dot.state.fl.us >
References: <#v************ **@TK2MSFTNGP11 .phx.gbl>
Subject: Re: IntPtr - what is this!?!?
Date: Mon, 8 Sep 2003 14:53:02 -0400
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#E************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: 156.75.83.5
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG XA06.phx.gbl!TK 2MSFTNGXA05.phx .gbl!TK2MSFTNGP 0
8.phx.gbl!TK2MS FTNGP10.phx.gblXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1832 61
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

Hi Nuno,

From MSDN:

A platform-specific type that is used to represent a pointer or a handle.
The IntPtr type is designed to be an integer whose size is
platform-specific. That is, an instance of this type is expected to be
32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit
hardware and operating systems.

The IntPtr type can be used by languages that support pointers, and as a
common means of referring to data between languages that do and do not
support pointers.

IntPtr objects can also be used to hold handles. For example, instances of
IntPtr are used extensively in the System.IO.FileS tream class to hold file
handles.

The IntPtr type is CLS-compliant, while the UIntPtr type is not. Only the
IntPtr type is used in the common language runtime. The UIntPtr type is
provided mostly to maintain architectural symmetry with the IntPtr type.

It's normally used when you are calling to non managed code ( API, COM,
etc )

Hope this help,

--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Esculcas" <ne*******@hotm ail.com> wrote in message
news:%2******* *********@TK2MS FTNGP11.phx.gbl ...
Hello,

I come from C++ and i now have to work with C#, and someone tell me

that
bye bye pointers but i think this is not true, i must convert a DIB image

in
something that i can use in C# (like Image or Bitmap) and the only thing i can do is a DIB into a IntPtr (a pointer). I do this with the platform
invoke method of Win32:

[DllImport("gdip lus.dll", ExactSpelling=t rue)]
internal static extern int GdipCreateBitma pFromGdiDib( IntPtr bminfo,
IntPtr pixdat, ref IntPtr image );

Now my little impression of what i do of it it's that the IntPtr is a
pointer to a Image!?!? right??!

If is, then how i do the cast (like in old good C++):
Image* pImg = (Image*) IntPtr_variable ;

Thanks
Nuno


--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 15 '05 #3

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

Similar topics

13
7436
by: Christian Westerlund | last post by:
Hi! I'm trying to use P/Invoke and a Method which takes an IntPtr where I am supposed to put an address to a method which the native method will use to communicate back to me. How do I convert a method to an IntPtr? / Christian
10
4658
by: Tamir Khason | last post by:
I have a pointer to array and I want to apply indexing to this Array so I have function (name it IntPrt Func) to go to certain member I can use (as C++) Func, but in C# I recieve an error "Cannot apply indexing with to an expression of type 'System.IntPtr'". How to get rid of it? TNX --
2
6872
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public static explicit System.IntPtr (long);
6
1566
by: active | last post by:
I downloaded the Win32 Library which saved me MUCH work. Some (All?) of the returned handles are typed int. As I used them I often changed them in my copy of win32 to IntPtr because an argument that used it was typed IntPtr. Now I wonder if a Handle make more sense being an integer or an IntPtr. I believe it's really an index rather than a pointer so Integer seems to
3
1781
by: Brian Henry | last post by:
how would you compare an IntPtr to check if it is zero? c++ example of what i want to do IntPtr hWndMdiClient; If (hWndMdiClient != IntPtr.Zero) {...} thanks
0
3956
by: Jørn Jensen | last post by:
Hey! I have an issue with creating bitmap from an IntPtr. The IntPtr is created from a Twain scanner, which seem to work perfectly in it's original state (the app is originally written by somebody else). It's when I add the I get an error. Extracts of my code and the error statement from the Visual Studio Debug bellow: Select Case cmd Case TwainCommand.CloseRequest EndingScan()
9
6190
by: pigeonrandle | last post by:
Hi, I'm trying to convert the following line to c# from VB6 If hrRapiInit >= 0 Then 'SUCCEEDED where hrRapiInit is declared as a Long. In c#, hrRapiInit must be declared as an IntPtr to fit in with the dll function i have imported, but obviously, the line
1
4211
by: dcurington | last post by:
I have to call a function. This is from the SDK: INT is_GetActSeqBuf (HIDS hf, INT* pnNum, char** ppcMem, char** ppcMemLast); I have demo C# code that works. Here is the prototype: private static extern int is_GetActSeqBuf (int hCam, ref int pnNum, ref IntPtr ppcMem, ref IntPtr ppcMemLast); And this is the way it is used in the C# code. IntPtr pMem = new IntPtr(); IntPtr pLast = new IntPtr();
0
2137
by: Charming12 | last post by:
Hi All, I have a strange problem and due to my inefficiency with IntPtr i am unable to figure it out. I have an structure something like: public struct Detail { public int age; public Detail(int _age)
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.