|
try to create your own function... eg.
public int NumUsed(Byte[] arr)
{
int Ctr = 0;
for (int i = 0; i < arr.GetLength(0); i++)
{
try
{
Byte tmp = arr[i];
Ctr++;
}
}
}
although i'm not pretty sure that this will work... but you can try.
|
|
|
|
|
There are 2 problems with this approach
1) You cant have a try without a catch or finally.
2) Exception's should not control the flow of a program.
You are better off using an ArrayList or some type of collection, as they usually resize internally asnd provide a Count property.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
You are totally wrong. There are even more problems
3) the return statement is missing
4) even a call like NumUsed(new Byte[100]) (nothing set in the array - just initialized) will result in 100
|
|
|
|
|
that's why i said I'm not sure it'll work...
|
|
|
|
|
So now you can be sure it'll not work
|
|
|
|
|
why instead don't you try
won't it work???
public int NumUsed(object[] arr)
{
int Ctr = 0;
for (int i = 0; i < arr.GetLength(0); i++)
{
if( arr[i]!=null)
Ctr++;
}
return Ctr;
}
and when you set one array position to unused do it like
arr[i] = null
of course you would have to use an object array but you could cast the object to byte when you
the real value
i think it will do
NOthing by now;)
|
|
|
|
|
pq4noeh wrote: of course you would have to use an object array
But where the heck would then be any reason not to use an ArrayList?
|
|
|
|
|
Use a List<> and read the .Count value.
|
|
|
|
|
An array doesn't have a concept of unused items. When you create the array all the items are initialized to their default value, for bytes that is zero. So all items are initialized, used, and have valid values.
Either you have to define a special value that means that the item is unused, so that you can test each value, or you have to keep track of which items are used using another variable or array.
Or use a list instead.
---
b { font-weight: normal; }
|
|
|
|
|
Thx ya'll for the education.
Donkaiser
|
|
|
|
|
I use code:
byte[] arraybyte = System.IO.File.ReadAllBytes("app.exe"); Ok
System.AppDomain dom = System.AppDomain.CreateDomain("newDomain");
dom.Load(arraybyte); not work
do not start.
and use this code:
byte[] arraybyte = System.IO.File.ReadAllBytes("app.exe"); Ok
System.Reflection.Assembly.Load(arraybyte); not work
How it need work?
Help please.
|
|
|
|
|
Is app.exe a .NET exe? If not, you cant do that.
|
|
|
|
|
app.exe is a .NET .
I don't know how to do next step.
Application .Net do not start from byte[].
Please help me.
|
|
|
|
|
Is there a reason you couldn't just call System.Diagnostics.Process.Start() ?
|
|
|
|
|
Class System.Diagnostics.Process.Start() need String type
But my application in byte[].
I don't start my application from hard disk.
My application in memory.
|
|
|
|
|
byte[] arraybyte = System.IO.File.ReadAllBytes("app.exe");
System.AppDomain dom = System.AppDomain.CreateDomain("newDomain");
Assembly assembly = dom.Load(arraybyte);
assembly.EntryPoint.Invoke(null, null);
That calls the Main() method.
|
|
|
|
|
I run this code.
byte[] arraybyte = System.IO.File.ReadAllBytes("app.exe");
System.AppDomain dom = System.AppDomain.CreateDomain("newDomain");
Assembly assembly = dom.Load(arraybyte);
assembly.EntryPoint.Invoke(null, null);
But in line
assembly.EntryPoint.Invoke(null, null);
have runtimeerror:
"TargetInvocationException was unhandled
Exception has been thrown by the target of an invocation."
Please help me!
|
|
|
|
|
Read the exception's InnerException. That'll tell you the actual error.
|
|
|
|
|
My code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Reflection;
namespace video
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
try
{
byte[] arraybyte = System.IO.File.ReadAllBytes("D:/work/C#/video/video/bin/Debug/zshchita.exe");
System.AppDomain dom = System.AppDomain.CreateDomain("newDomain");
Assembly assembly = dom.Load(arraybyte);
assembly.EntryPoint.Invoke(null, null);
}
catch (Exception e)
{
string st = e.InnerException.ToString();
}
}
}
}
st :
System.InvalidOperationException: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.
at System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(Boolean defaultValue)
at video.Program.Main() in D:\work\C#\video\video\Program.cs:line 16
Program.cs :
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace video
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
line 16 Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
???
Please help me!
-- modified at 4:51 Friday 19th May, 2006
|
|
|
|
|
I can't run that since I have neither the other portion of the form nor zshchita.exe, but just judging from the exception, it looks like you have to remove the line that calls Application.SetCompatibleTextRenderingDefault from zshchita.exe. It's probably in Main().
|
|
|
|
|
My be out of memory?
Any application i was run in TotalComander and Ok result.
But from my application is error.
If this veri hard then stop this idea?
I don't know how to do this.
But i was veri wont to do this!
God bless you. He leves you veri mach.
|
|
|
|
|
I'm pretty sure you can fix it by deleting the Application.SetCompatibleTextRenderingDefault() from the other exe.
|
|
|
|
|
i deleting this but problem don't go out.
Next message was this :
System.InvalidOperationException: Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Bblank.Program.Main()
|
|
|
|
|
Try what the error says...
On the line where it says Application.Run(), change it to form.ShowDialog().
|
|
|
|
|
hi all,
let's assume i have form named mehmet and a mainmenustrip on that form like this:
'Properties'
>property1
>property2
>property3
>...
mehmet.MainMenuStrip.Items[0].ToString() gives me the name : <properties>
how can i get any name under Properties ? what should i write instead of mehmet.MainMenuStrip.Items[0].ToString() to get property3 as a result ¿
|
|
|
|