473,718 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IntPtr and fixed


Hi All

Is IntPtr a managed or unmanaged data type in c#

Do I need to be doing
Intptr = IPtr
fixed(void * ptr = (void *)IPtr
....
to avoid relocation? or can I use

void *ptr = (void *)Iptr without fixed

thank yo
vipin
Nov 15 '05 #1
3 5294
Is IntPtr a managed or unmanaged data type in c#?
Managed. C# only produces managed code, you can't have any unmanaged
types.

Do I need to be doing
Intptr = IPtr;
fixed(void * ptr = (void *)IPtr )
{
....
}

to avoid relocation? or can I use
void *ptr = (void *)Iptr without fixed?

Most likely no, but it depends on what the IntPtr is pointing at. I
assume you wouldn't have an IntPtr pointing to something managed
unless you had already pinned it. The first piece of code won't work
though.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
IntPtr points to a View returned by calling DLLImport MapViewOfFIle from kernel32.dll

I am compiling the code with /unsafe switch

vipin
Nov 15 '05 #3
IntPtr points to a View returned by calling DLLImport MapViewOfFIle from kernel32.dll.


Then there's no need to pin anything. The handle refers to an
unmanaged resource that's not affected by the GC anyway.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4

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

Similar topics

2
29636
by: Logan McKinley | last post by:
I have a third party Dll with a function which requires an IntPtr but the data is in a byte array. I need to get the IntPtr for this byte array so I can pass it into the function. Thanks in advance, ~Logan
0
288
by: vipin | last post by:
Hi All Is IntPtr a managed or unmanaged data type in c# Do I need to be doing Intptr = IPtr fixed(void * ptr = (void *)IPtr ....
1
3465
by: vipin aravind | last post by:
Hi, In C#, I do DllImport of MapViewOfFile(...) which will return IntPtr. The (void *) operator gives me the pointer way of working on the memory. My question is do I need to use fixed(void *ptr = (void *)intptr) { }
13
7427
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
4648
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 --
1
25602
by: zishen yan | last post by:
Hello, I have a question confused me a long time. I am working on DirectDraw .NET a while. And I want to copy data to surface, but I found Surface.Lock return System.Array. I tried to cast it to byte,byte, but in vain( It will crash without any exception). Before I saw somebody said he used unsafe code to slove the problem on newsgroup, but without any sample codes.
7
7847
by: justin.kruger | last post by:
I am having a problem with exchanging handles with c# and the "CP210xManufacturing.dll" in a device wrapper that i am working on. I have created a wrapper class to address some of the functions in the dll, but not all of them yet. To my knowledge they should be almost correct, however this is my first try at exchanging handles between legacy code and a managed enviroment. It seems that I am able to get a handle from "CP210x_Open,"...
0
1429
by: cewood | last post by:
Hi, I was hoping someone could help me with the following: I'm writing code to try and get a image from a USB camera mfg. dll. Here's the dll function: SDK_API MTUSB_GetCurrentFrame( DEV_HANDLE DevHandle, int FrameType, unsigned char *Buffer ); Here's my C# wrapper: public IntPtr GetCurrentFrame(FRAME_TYPE FrameType)
2
8025
by: O.B. | last post by:
I have a class that has an Explicit StructLayout. In the constructor below, I am copying data from a byte array onto this class so as to initialize all the explicit attributes of the class. What I don't like is the overhead of allocating memory for a temporary variable (pData) when I want to marshal the data in the rawData array directly into the current object. Would there be a way to get an IntPtr directly to the current object? ...
0
8827
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
8723
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9207
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
9053
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7987
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...
1
6652
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4741
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2122
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.