Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Pointers

Status
Not open for further replies.

phaseshift

IS-IT--Management
Dec 13, 2004
45
US
I need to read a file into memory then get a pointer for the files memory location to pass to a C++ dll. I know how to get a pointer in C++ but not not in C#.

Any thoughts on where to start. Google hasns't turned anything good up.

Also it there a way to do this without getting into unsafe code?
 
You will be writing unsafe code (by definition, using pointers is unsafe). To go from an array of byte to a pointer to that memory, you do something like this:
Code:
static unsafe void DoSomething(byte[] src)
{
  // Check for null, etc. here

  // Use fixed keyword to prevent memory from being GC'd or relocated
  fixed (byte* pSrc = src)
  {
    byte* ps = pSrc;

    // Do unsafe stuff with your pointer to byte here
  }
}

Hope this helps.
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thats what I am doing so it must be in the C++ .dll (a third party) so I have to get with them.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top