|
You could use reflection, but as for showing the actual code being run, I doubt that. I mean, you'd have to write code that executes after every statement, and shows it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You can use .NET Profiling API to rewrite the IL code when it is about to JIT.
So you can add such statements with that..
but you have to know a bit or two about IL.
|
|
|
|
|
Good Day,
I am working in an encryption utility as a school project. I'm all done with the byte manipulations and stuffs and just need to write the data as a file. I have already conceptualized the File Structure and is coded as:
[StructLayout(LayoutKind.Sequential)]<br />
struct LockFile<br />
{<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]<br />
public string MagicNumber;<br />
public Hashtable IncrementalMappingArray;<br />
}
I need to Serialize that structure using this function I found somewhere:
private static byte[] RawSerialize(object anything)<br />
{<br />
int rawsize = Marshal.SizeOf(anything);<br />
IntPtr buffer = Marshal.AllocHGlobal(rawsize);<br />
Marshal.StructureToPtr(anything, buffer, false);<br />
byte[] rawdatas = new byte[rawsize];<br />
Marshal.Copy(buffer, rawdatas, 0, rawsize);<br />
Marshal.FreeHGlobal(buffer);<br />
return rawdatas;<br />
}
Then I write it as file:
LockFile theLockFile = new LockFile();<br />
theLockFile.MagicNumber = "myLock";<br />
theLockFile.IncrementalMappingArray = IMA;<br />
<br />
byte[] LockFileStream = RawSerialize(theLockFile);<br />
<br />
MessageBox.Show(LockFileStream.Length.ToString());<br />
<br />
<br />
string Filename = Path.GetFileNameWithoutExtension(txtPath.Text);<br />
<br />
string LockFilePath = Path.GetDirectoryName(txtPath.Text);<br />
<br />
File.WriteAllBytes(LockFilePath + "\\" + Filename + ".flk", LockFileStream);
But it always write the same value with 4 bytes in it. But the IMA (Hashtables) contains a lot of key-value pair. (Like 5mb).
Do I need to convert the hashtable to a byte[] first?
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
I have a couple of questions.
1) What are you encrypting, and why a Hashtable?
2) Why did you choose a struct?
3) Have you checked the post-RawSerialize() byte arrays to verify sizes?
4) Are you using unmanaged code in your project?
And recommendations.
1) Go back on the Net and study up on the difference between ValueTypes and ReferenceTypes.
2) Use caution when you snag some code, you'll have to understand what's going on.
What I think is going on here is a boxing issue. You're using a struct to hold data, however your serialization routines are calling for Object. So, when you pass in your struct it is boxed, turning it into a reference type. Then you're calling Marshal.StructureToPtr passing in the boxed value. In essence you're serializing the address of your struct. That's why it's writing the 4 characters (8 bytes) to the file.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
carbon_golem wrote: What are you encrypting, and why a Hashtable?
Long Long Discussion.
carbon_golem wrote: 2) Why did you choose a struct?
Is there any other option?
carbon_golem wrote: 3) Have you checked the post-RawSerialize() byte arrays to verify sizes?
Yes, the output byte lenght is correct.
carbon_golem wrote: 4) Are you using unmanaged code in your project?
I'm not sure...
carbon_golem wrote: Go back on the Net and study up on the difference between ValueTypes and ReferenceTypes.
I'm sure I know the difference between the two.
carbon_golem wrote: Use caution when you snag some code, you'll have to understand what's going on.
I've already analyzed that piece of code and found out that I don't really need it.
So what I did is a simpler approach:
[Serializable]<br />
struct LockFile<br />
{<br />
public string MagicNumber;<br />
public Hashtable IncrementalMappingArray;<br />
}
<br />
private byte[] RawSerialize(object anything)<br />
{<br />
MemoryStream Stream = new MemoryStream();<br />
BinaryFormatter BF = new BinaryFormatter();<br />
BF.Serialize(Stream, anything);<br />
byte[] Data = Stream.ToArray();<br />
return Data;<br />
}<br />
<br />
private object RawDeserialize(byte[] byteStream)<br />
{<br />
MemoryStream Stream = new MemoryStream(byteStream);<br />
BinaryFormatter BF = new BinaryFormatter();<br />
object thisObject = BF.Deserialize(Stream);<br />
return thisObject;<br />
}
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Ian Uy wrote: carbon_golem wrote:
2) Why did you choose a struct?
Is there any other option?
Yes.
Ian Uy wrote: carbon_golem wrote:
3) Have you checked the post-RawSerialize() byte arrays to verify sizes?
Yes, the output byte lenght is correct.
Hmmm... I checked, and I didn't think they were.
Ian Uy wrote: carbon_golem wrote:
Use caution when you snag some code, you'll have to understand what's going on.
I've already analyzed that piece of code and found out that I don't really need it.
Because it didn't work?
Your new approach is better. Does it work for you now?
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
carbon_golem wrote: Your new approach is better. Does it work for you now?
Yes sir it did.
But when I use the same method on other application to deserialize the file, I get an "Assembly cannot be loaded" error.
It does work on the same application though.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Ahhh... If you're putting your objects into the Hashtable for serialization, you'll need to have the Assembly that those objects are in available to the Deserializing program/assembly.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
<>Hi,
This is ravindra ,I created the following function and able to execute the followed query
successfully in sql plus but when i try to execute the same query through code,getting error like
Unspecified error
Oracle error occurred, but error message could not be retrieved from Oracle.
Data type is not supported.
Create or Replace Function convert_time(datetime in timestamp, tz1 in varchar2, tz2
in varchar2)
Return timestamp with time zone
as
retval timestamp with time zone;
Begin
retval := from_tz(datetime, tz1) at time zone tz2;
return retval;
End;
select convert_time(to_timestamp('01/01/2006 23:45','mm/dd/yyyy
hh24:mi'),'US/Eastern','Turkey') from dual;
the .net code as follows
string conn = "Provider=MSDAORA.1;Password=;User ID=;Data Source=naradaon;Extended
Properties=Server=naradaon";
OleDbConnection con = new OleDbConnection(conn);
con.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select from_tz(to_timestamp('01/01/2006
23:45','mm/dd/yyyy hh24:mi'),'-05:00') as hio from dual", con);
da.Fill(ds);
Please help me
thank you
<>
|
|
|
|
|
Try writing a parameterised query. I'm surprised this SQL works, I thought you needed select *, not just select. Could be an Oraclism tho.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Use OracleDataAdapter instead.
(using Oracle.DataAccess.Client)
string conn = @"...."; // make sure you use the correct one
string strSel = @"select from_tz(to_timestamp('01/01/2006 23:45','mm/dd/yyyy hh24:mi'),'-05:00') as hio from dual";
OracleDataAdapter da = new OracleDataAdapter(strSel, conn);
DataSet ds = new DataSet();
da.Fill(ds);
SkyWalker
modified on Thursday, May 1, 2008 10:52 AM
|
|
|
|
|
Hi,
For those who don't know, in Windows Vista when you hold shift down and right click a folder a few hidden options (Copy as Path, Command Wind Here)
I was wanting to implement a similar feature in my program - mainly for debugging purposes.
For example on my grids when you right click on the Header it displays all column names and lets you show and hide them. I would like it so if shift was pressed it would put the width of the column after it.
Any ideas?
|
|
|
|
|
Figured it out - ModifierKeys == Keys.Shift
|
|
|
|
|
Hi all,
Now I need a solution to open the internet explorer in a new window.Also I need to display message "PROCESS OVER"/"ERROR" Depending upon the value taken from the user in the newly created window.
plz help,
regards,
syamooo...
|
|
|
|
|
Process.Start("http://www.codeproject.com");
will open a new IE window. If you open an external IE window, you can't interact with it. If you want to, then you need to put a web browser control on a form, and show the page in that.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Chris,
thanks for ur answer.Also i want to know how to pass parameters to page.For eg:there is page which contains a function which will executed on the page_load event.If it takes an argument as a string and the function will simply display it in a label.My question is how to pass the input string to the function from a page .
|
|
|
|
|
Oh, this is an ASP.NET question, or just the site you launch from your winforms app is your own to control ? The way to pass parameters to a web page is to put them on the query string.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Process.Start("http://www.codeproject.com");
This opens the page in the default browser (Firefox on my machine).
I think the correct way is Process.Start("iexplore.exe");
|
|
|
|
|
Yeah, I said it opens the default browser. If you want to force IE, you need to pass the URL as an argument, that may work.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Yeah, I said it opens the default browser.
Actually you didn't say that anywhere
|
|
|
|
|
you're right
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: will open a new IE window
Thats not quite true. If there is an open window it will hijack it, and redirect to the supplied webpage. Actually calling iexplore.exe will definately open a new window. I did write up some code a while ago, to find the users default browser and start a new instance of it on a webpage. I hate when something starts taking over my browser windows.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
I have written a C# app, where I used WebBrowser control to visit any webpage. If there is a download in this page, and I want to download it IE7 default download manager pops up and starts download. But I want to use custom download manager (viz. one embedded with my app) to download file from webbrowser control.
How to solve the problem? Please help me. I am stuck there.....
Thank you in advance.
Anindya Chatterjee
|
|
|
|
|
Right then. WebBrowser has an event for Navigating , which gets called just before the control starts redirects to the new url.
You'll need to use the event, and check the extension of the file being downloaded. If the extension is any kind of webpage (htm, html, asp, etc) then you can just ignore it. If the extension is something else (rar, mp3, doc, etc) then you will need to cancel the event, and start your custome downloading code on the url.
A quick example:
void WebBrowser1Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if(e.Url.AbsoluteUri.EndsWith(".html"))
{
return;
}
e.Cancel;
}
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
what if it goes to an ASP, PHP, ASPX, DHTML, SHTML, JSP, ect.. page?!?!
You "could" create a web client object that spits it's request into the webbrowser control to be displated. Then you have access to the HTTP headers! but, then you can't port it over to the compact framework without lots of work openNETCF library only to find a bug in openNETCF and have your project grind to a halt to be canceled
|
|
|
|