|
Hi.
How can we pass a pointer ( like byte* pointerToImage ) to a method as an argument ?
I've tested this way :
void mainMethod()
{
unsafe
{
.
.
byte* pointerToImage = (byte*)(void*)Scan0;
checkOut( ref pointerToImage );
.
.
}
}
void checkOut(ref byte* pointerToImage)
{
unsafe
{
.
.
.
}
}
But it hasn't worked.
The error :
Pointers and fixed size buffers may only be used in an unsafe context
Could you guide me ?
Tank you.
|
|
|
|
|
You need to mark the method unsafe.
unsafe void checkOut(ref byte* pointerToImage)
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Thank you Expert
|
|
|
|
|
hi
how can I enable run ActiveX in web browser control in C#
(system.windows.forms.webbrowser)
|
|
|
|
|
I wish to have a TextBox which it can fire the list of AutoCompleteCustomSource when the TextBox is clicked without enter any text.
But i can't find any method that can use to trigger AutoComplete list during run time.
Pls advise. Thanks
|
|
|
|
|
hi there, im new to the forums. Im creating a dice game. however my attack logic is some what flawed. I was having trouble with random numbers generating the same number so i placed them inside there own class hoping it would then generate diffrently. however now the same number generates eg 66 + 66. this is a rather pain as my whole game will contain about 7 randoms.All being called ont he same button.Another problem im having (///////second code///////) Where the random only generates and pulls up if (dilemma == 1). Just a note im fairly new to c# so if you could explain any fixes you come up with i'd really appreciate it.
regards ant
public class Globals4
{
public static int user;
public static Random uc = new Random();
}
public class Globals3
{
public static int comp;
public static Random cc = new Random();
}
lblwarning.Text = "Warning";
MessageBox.Show("personal attack");
int userresult = Globals4.user + Globals.army;
Globals3.comp = Globals3.cc.Next(1, 100);
Globals4.user = Globals4.uc.Next(1, 100);
Globals4.user = Globals4.user + Globals.army;
MessageBox.Show("Computer rolled " + Globals3.comp + " You rolled " + Globals4.user + " with an army strength of " + Globals.army + " equals " + userresult + "");
//////////////////////////////SECOND CODE//////////////////////////////////////
dilemma = dl.Next(1, 1);
DialogResult res;
if (dilemma == 1)
{
res = MessageBox.Show("marriage", "Dilemma", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
Globals.notoriety -= 1;
}
else if (res == DialogResult.No)
{
Globals.notoriety += 1;
}
if (Dilema == 2)
{
res = MessageBox.Show(" force?", "check", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
Globals.notoriety -= 1;
}
else if (res == DialogResult.No)
{
Globals.notoriety += 1;
}
//EDIT i forgot to add this is c# visual i believe its called .net (not the console)
|
|
|
|
|
Random does not produce actually random values, it's a pseudo-random generator. Seed your Random with time related value. Something like that new Random(DateTime.Now.GetHashCode()); or new Random(Environment.TickCount);
Eslam Afifi
|
|
|
|
|
im afraid i dont really understand could you mock me up an example of 2 randoms in one method?
|
|
|
|
|
Hi,
Are you by any chance a graduate of the school of "I'm absolutely not going to read the documentation" programming? The reason I ask is that the title of your original post was the answer, i.e you knew that you wanted to seed the random number generator.
When you were told how to do it, you asked for code. I have just opened the documentation for the Random class and on the introductory page is a full example showing more than one method of seeding the generator.
If you had just done the same then your problem would have been solved in less time than it took to post the question.
Alan.
|
|
|
|
|
well that was a nice response,I presume your from the old school of elitist programmers who bash new people to a language or just say try google Considering i've been looking into this for 3 days hence why i knew what i was doing just not sure how to impliment it and not really understooding the code thats why i posted. I also asked for a interpretation of the code as a general rule to work from not for someone to do it for me. Im sorry ive my lack of knowledge causes you offence but as a rule of thumb forums are to learn from
|
|
|
|
|
Hi,
A lack of knowledge does not offend me in the slightest and I am more than willing to help. The point I made was that you used "Random seeds?" for the title of your post yet you appeared not to have done any research on that very topic.
You must have thought it a bit odd that something called a random number generator was giving the same sequence every time it was used.
Surely the place to start was with the documentation.
Alan.
|
|
|
|
|
As I have understood your post, you are having troubles with random numbers generation.
Here is a solution, that may be helpful.
As it has been noted, a seed number is used to start numbers generation. In most occasions this number is dependent on current time, for example, Environment.TickCount can be such a seed. What happens sometimes, is that number sequences are being generated too fast, so that the time-related seed is not changed. This may result in troubles, when you are generating numbers not in one sequence. Here is a code example. We are generating an array of objects typed sample , and each object contains a set of randomly generated numbers.
class sample
{
double[] dblMyArray = new double[20];
public sample()
{
Random rndObj = new Random(Environment.TickCount);
for (int i = 0; i < dblMyArray.Length; i++)
dblMyArray[i] = rndObj.NextDouble();
}
}
class Program
{
static void Main(string[] args)
{
sample[] mainArray = new sample[10];
for (int i = 0; i < mainArray.Length; i++)
mainArray[i] = new sample();
}
}
Now, what will happen is a sad fact: all the objects in mainArray will have THE SAME values in dblMyArray . This is because modern computations are fast, and time related seed cannot change fast enough. You may run this code and check out the values.
If you have a similar problem, the solution is to sleep a program for a short time, I used 1ms. This way the seed number will change, and each time you'll have different sequences.
|
|
|
|
|
i just mocked up mine i have a feelings its wrong but cant test atm
public class Globals2
{
double[] dblMyArray = new double[20];
}
public class Globals3
{
public static int comp;
public static Random cc = new Random(Environment.TickCount);
for (int i = 0; i < dblMyArray.Length; i++)
dblMyArray[i] = cc.NextDouble();
}
public class Globals4
{
public static int comp;
public static Random uc = new Random(Environment.TickCount);
for (int i = 0; i < dblMyArray.Length; i++)
dblMyArray[i] = cc.NextDouble();
}
lblwarning.Text = "Warning";
MessageBox.Show("personal attack");
int userresult = Globals4.user + Globals.army;
sample[] mainArray = new sample[10];
for (int i = 0; i < mainArray.Length; i++)
mainArray[i] = new sample();
Globals3.comp = Globals3.cc.Next(1, 100);
Thread.Sleep(10);
sample[] mainArray = new sample[10];
for (int i = 0; i < mainArray.Length; i++)
mainArray[i] = new sample();
Globals4.user = Globals4.uc.Next(1, 100);
Globals4.user = Globals4.user + Globals.army;
MessageBox.Show("Computer rolled " + Globals3.comp + " You rolled " + Globals4.user + " with an army strength of " + Globals.army + " equals " + userresult + "");
|
|
|
|
|
just got round to trying it with no luck
|
|
|
|
|
just an update i got it working with the threadtime scheduling thanks for the tip
however the 2nd bit of code still isnt working so i placed it in its own fucntion
/ rolling function
public class Globals6
{
public static int dilemma = 0;
public void random1()
{
Random dl = new Random(Environment.TickCount);
Globals5.dilemma = dl.Next(1, 2);
DialogResult res;
if (Globals5.dilemma == 1)
{
res = MessageBox.Show("Ban same sex marriage", "Dilemma", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
Globals.notoriety -= 1;
}
else if (res == DialogResult.No)
{
Globals.notoriety += 1;
}
if (Globals5.dilemma == 2)
{
res = MessageBox.Show("Political protest, do you use essesive force?", "check", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
Globals.notoriety -= 1;
}
else if (res == DialogResult.No)
{
Globals.notoriety += 1;
}
}
}
}
}
and call it by putting random1(); in main how ever i get this error
Error 2 The name 'random1' does not exist in the current context C:\Users\ant\Documents\Visual Studio 2008\Projects\game\game\Form1.cs 119 17 game
|
|
|
|
|
bump plz ive managed to get it working just not randomizing the second code it just plays message 1 constantly
|
|
|
|
|
I seem to be having an issue with this statement, I keep getting a 'datatype mismatch in criteria expression' error. The ID in the expression is a string, but I have tried converting it to an int with no luck. IN the table the ID field is an autonumber int. Anyone see any problems?
public void playSelection(string ID)
{
OleDbConnection musLibConn = new OleDbConnection();
utility util = new utility();
musLibConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\GeneSys\Library.mdb";
musLibConn.Open();
OleDbCommand selLib = new OleDbCommand("SELECT Path FROM Library WHERE ID = '"+ID+"'", musLibConn);
OleDbDataReader drLib = selLib.ExecuteReader();
int idxPath = drLib.GetOrdinal("Path");
WMP.URL = drLib.GetValue(idxPath).ToString();
}
|
|
|
|
|
IDs are typically numbers and therefore should not be in quotes.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
jetspike wrote: in form2 I create an instance of form1
so Form1 creates Form2, and Form2 creates yet another Form1; how many Forms do you actually see? if you create three but only see two, is that sufficient reason to believe the third one will magically coincide with the first? how would the second Form1 relate to the first Form1, except for being twins?
It is sickening to see this kind of posts all the time, it just indicates people are not willing to study the basic stuff, read a book on a programming language, then read a book on object orientation, then read some of the hundreds of articles on the subject available here on this site,. until they understand what they are doing.
And don't bother to reply.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
jetspike wrote: Form1 form1 = new Form1();
As has been said, people post this stuff all the time, and what it tells us is that you understand close to nothing about the code you are writing. Read a book on OO and a book on C#, learn some basics.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
hi
How Can i Change the Image instance Size
it could not be used as following
image.Size.Height=200;
it will raise an exception :
"Cannot modify the return value of 'System.Drawing.Image.Size' because it is not a variable"
so i tried to use the following code:
<br />
int size = image.Size.Height;<br />
size= 200;<br />
and also :
<br />
Size size = image.Size;<br />
size.Height= 200;<br />
but it does not work
please help me
thanks
|
|
|
|
|
It seems you are not understanding some basics of imaging. To resize an image, you need to specify a method to use, and then you need to build the image at the new size. Changing just the height is impossible because, apart from other things, you're not defining what you really want. Assuming the current height is < 200, do you want a new blank area under the image, or do you want to stretch it ? If it's greater, do you want to crop the image, or compress it ? In either case, changing height without changing width and making the image fit, will distort it.
You need to create a new bitmap of the size you want, select it into a Graphics object, and use that to draw your old image onto the new one, either distorting it, or drawing just the portion you want onto the portion of the new bitmap as required.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
I want to know how can save an image into SQL Server and retrive it again into Picture control using SqlDataReader? here is my code to read from the database and now I need to read the image in addition to the data I ma reading:
private void get_staff_info()
{
this.Cursor = Cursors.WaitCursor;
sql_connection = new SqlConnection("Data Source=.\\SQLEXPRESS;initial catalog=ssis_database;integrated security=true;");
sql_connection.Open();
sql_command = new SqlCommand("sp_get_staff_info_by_id", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
sql_command.Parameters.Add("@staff_id", SqlDbType.Int).Value = staff_id;
sql_reader = sql_command.ExecuteReader();
if (!sql_reader.HasRows)
{
MessageBox.Show("staff not found!!", "error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
if (sql_reader.Read())
{
lblCPR.Text = sql_reader["staff_cpr"].ToString();
lblFullName.Text = sql_reader["staff_name"].ToString();
lblBirthday.Text = Convert.ToDateTime(sql_reader["staff_birthday"]).ToString("dd-MMM-yyyy");
TimeSpan age = DateTime.Now - Convert.ToDateTime(sql_reader["staff_birthday"]);
int years = age.Days / 365;
int months = (age.Days - (years * 365)) / 30;
string strAge = String.Format("{0}y", years);
lblBirthday.Text += " [" + strAge + "]";
lblGender.Text = sql_reader["gender_name"].ToString();
lblNationality.Text = sql_reader["country_name"].ToString();
lblFlat.Text = sql_reader["staff_address_flat"].ToString();
lblBuilding.Text = sql_reader["staff_address_building"].ToString();
lblRoad.Text = sql_reader["staff_address_road"].ToString();
lblBlock.Text = sql_reader["staff_address_block"].ToString();
lblTelephoneHome.Text = sql_reader["staff_telephone_home"].ToString();
lblTelephoneMobile.Text = sql_reader["staff_telephone_mobile"].ToString();
lblTelephoneMobile2.Text = sql_reader["staff_telephone_mobile2"].ToString();
lblEmailAddress.Text = sql_reader["staff_email_address"].ToString();
lblGrade.Text = sql_reader["grade_name"].ToString();
lblStep.Text = sql_reader["step_name"].ToString();
lblSalary.Text = Convert.ToDecimal(sql_reader["staff_salary"]).ToString("BD #,###,##0.000");
lblBank.Text = sql_reader["bank_name"].ToString();
lblBankAccount.Text = sql_reader["staff_bank_account"].ToString();
sql_reader.Close();
}
}
this.Cursor = Cursors.Default;
}
|
|
|
|