473,467 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unsafe code problem

I have two piece of unsafe code. In the first one I'm getting the byte*
pointer of a Bitmap data, and the second one in inside a loop that uses that
byte* pointer to set the data in the Bitmap.

The trouble is that that each of this pieces of code are bound by a
different unsafe section, therefore I'm getting an error that the second
unsafe section does not "The name 'refBuf' does not exist in the current
context"

////////////////////////////////////////////////////////////////
Bitmap img = new Bitmap(100, 200,
System.Drawing.Imaging.PixelFormat.Format32bppRgb) ;
int maxLines = 1234;
System.Drawing.Imaging.BitmapData refData = img.LockBits(
new Rectangle(0, 0, img.Width,
img.Height),

System.Drawing.Imaging.ImageLockMode.WriteOnly, img.PixelFormat);
unsafe
{
byte* refBuf = (byte*)refData.Scan0.ToPointer();
}
for( int line= 0; line< maxLines ; ++line)
{
Array buff = GetBuffer(line);
unsafe
{
// Copyieng the buff content to the refBuf...

// In here the refBuf is unknown !!!!
}
}
img.UnlockBits(refData);
////////////////////////////////////////////////////////////////

I need to set the byte* refBuf only once outside of the loop, but I also
need to use the byte* refBuf inside the loop.

What should I do to make this error go away?
--
Thanks
Sharon
Mar 28 '07 #1
0 1234

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

Similar topics

2
by: Elidel | last post by:
Is the use of a COM object in a c# program considered 'unsafe' code ? Does the method that calls the COM object need the 'unsafe' keyword ? Is code that calls a COM object considered unmanaged?...
0
by: Wayne Gibson | last post by:
Hi, Firstly sorry for cross posting, but I didn't know which would be the best group to post too.. I was wondering if anybody could help me with a problem that I have. I have created a...
3
by: Andre | last post by:
if I have an unsafe method that takes in two arrays, performs some operations and returns; I know that the garbage collector will not collect objects allocated inside the unsafe method. However, if...
8
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and...
4
by: Jon Milner | last post by:
How do I declare that my code is unsafe? Sorry the help files at my University have not been installed!
17
by: Bradley1234 | last post by:
Sorry if this is obvious, but Ill ask... Is there a new way of using pointer operations in C# ? Ive got a Deitel book on C# that neither mentions the word "pointer" nor "unsafe" in the index....
0
by: Robert Rae | last post by:
I'm calling the C++ function below from C#: GENCLIENT_API int CleanseEx(char ncSystem, const char *strServer, const char **pNames, const char **pInputData, const char **pRules, char...
10
by: Sergei | last post by:
Can anyone explain why PostMessage to a Windows Form is considered unsafe and raises InvalidOperationException? I can get rid of that setting CheckForIllegalCrossThreadCalls to false and...
2
by: Daniel Knöpfel | last post by:
Hi all I need to adapt an Msbuild script to compile a visual studio 2005 solution (including several projects and a website). The application is written in C# and using .NET 2.0. Due to late...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.