|
Hello
Please don't take any offence when I say it's a very bad piece of code you got there!! Really! You got to declare your Webbrowser as a member of your forms class. And why the console if you got a browser on a form?!! Not to mention the main method!! You don't want to display it make visible = false; but I don't think it will ever load anything this way?!! The WebBrowser object dies the moment this Go method finishes, that's why it doesn't load anything.
To make the webbrowser really works:
1- Make a form and put it on it -even if invisible- using the toolbox
2- Handle the DocumentCompleted event, it does fire.
3- If you don't want to handle it, you can handle ProcessChanged event
There is a workaround to make Webbrowser work on console but I don't recommend it!!
Regards
|
|
|
|
|
You don't need the web browser to do that. Just do the following:
public string GetWebPage(string url)
{
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
Stream responseStream = null;
Encoding encode = null;
StreamReader webPageStream = null;
string webPageText = "";
try
{
webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webResponse = (HttpWebResponse)webRequest.GetResponse();
responseStream = webResponse.GetResponseStream();
encode = Encoding.GetEncoding("utf-8");
webPageStream = new StreamReader(responseStream, encode);
webPageText = webPageStream.ReadToEnd();
}
catch (Exception e)
{
MessageBox.Show("Error : " + e.Message);
}
finally
{
if (webPageStream != null)
{
webPageStream.Close();
webPageStream.Dispose();
}
if (responseStream != null)
{
responseStream.Close();
responseStream.Dispose();
}
if (webResponse != null)
{
webResponse.Close();
}
}
return webPageText;
}
|
|
|
|
|
We managed to workaround previous problem (http://www.codeproject.com/script/comments/forums.asp?msg=1665538&forumid=1649&mode=all&userid=1533852#xx1665538xx) with Nader help, but now, another problem.
Now it's a problem to pass the address of structure array.
My colleague and I developing a program. He is dealing with unmanaged code and Iam dealing with managed code.
So we tried this:
public static extern uint bbox_table_get(uint parent_id, uint struct_size, ref Array data, ref StringBuilder data_name);
Array data = Array.CreateInstance(typeof(bb.DATA), count);
bbox_table_get(id, (uint)Marshal.SizeOf(typeof(DATA)), ref data, ref data_name);
and this:
public static extern uint bbox_table_get(uint parent_id, uint struct_size, ref DATA []data, ref StringBuilder data_name);
DATA []data = new DATA[count];
bbox_table_get(id, (uint)Marshal.SizeOf(typeof(DATA)), ref data, ref data_name);
and don't work.
We can compile in both cases, but program breaks before he get to dll.
In C++ it should be like:
UINT bb_table_get(UINT parent_id, UINT struct_size, DATA *data, wchar_t *data_name);
DATA *data = new DATA[count];
bbox_table_get(id, sizeof(DATA), data, data_name);
And DATA struct looks like:
<pre
public struct="" data
{
="" public="" uint="" data_id;
="" data_type;
public="" data_size;
};<="" pre="">
Thanks.
-- modified at 21:25 Thursday 14th September, 2006
|
|
|
|
|
Hello
First, arrays in C# are actualy references. So try to keep it simple first:
public static extern uint bbox_table_get(uint parent_id, uint struct_size, bb.DATA[], ref StringBuilder data_name);
bb.DATA[] data = new bb.DATA[count];
bbox_table_get(id, (uint)Marshal.SizeOf(typeof(DATA)), data, ref data_name);
...see if that works! If it doesn't, what is exactly the error message?
Regards
|
|
|
|
|
This is it...
It works.
Thank you.
|
|
|
|
|
I have another problem. Sorry for this problem frequency.
public static extern uint bbox_table_get(uint parent_id, uint struct_size, DATA []data, char []data_name);
DATA []data = new DATA[count];
bbox_table_get(id, (uint)Marshal.SizeOf(typeof(DATA)), data, data_name);
We can compile it with this, program call a dll function, data addresses are all OK and dll fills all data, but, for some reason, at the ending of the function, data arent sent to the application.
Data are sent as constants, accually read-only.
how can I avoid this?
Thanks...
|
|
|
|
|
Hello
Replying to your message won't send me any email notification of your post. If I weren't browsing old posts I wouldn't have noticed that you had this question.
Anyway, about your issue now.
Kasic Slobodan wrote: dll fills all data
Then...
Kasic Slobodan wrote: data arent sent to the application
Then
Kasic Slobodan wrote: Data are sent as constants, accually read-only
I must admit I'm lost!! Data are sent or not? and what do you mean by constant? What happens when you try to manipulate that data?
Regards
|
|
|
|
|
Nader Elshehabi wrote: Replying to your message won't send me any email notification of your post. If I weren't browsing old posts I wouldn't have noticed that you had this question.
I didn't realised this. Thanks for the info and sorry.
Iam lost too. I didn't understand my colleague quite well.
Anyway, he said to told you that data is not returned from dll to the application.
Hope this is more understandable...
|
|
|
|
|
1- Change the declaration of the import to:
public static extern uint bbox_table_get(uint parent_id, uint struct_size, [MarshalAs(UnmanagedType.SafeArray)] bb.DATA[] data, ref StringBuilder data_name);
2- If it didn't work try to put some data in your array's first element before sending it, and see if the data is the same or was it changed.
Regards
|
|
|
|
|
My colleague said:
I can’t send data_name as ref StringBuilder because I get some error when function is called and it works fine if I use char []data_name so please don’t focuse on that.
[MarshalAs(UnmanagedType.SafeArray)] did not help
When I said that data is sent as const I meant that data is sent from application to dll like it’s a const and because of it, data is not returned from dll.
Because I don’t speak English very good I’ll give you an example:
DATA []data = new DATA[count];
data[0].id = 20;
char []data_name = new char[data_size];
data_name[0] = ‘t’;
data_name[1] = ‘e’;
data_name[2] = ‘s’;
data_name[3] = ‘t’;
bbox_table_get(id, (uint)Marshal.SizeOf(typeof(DATA)), data, data_name);
data[0].id = 5;
data_name[0] = ‘b’;
data_name[1] = ‘r’;
data_name[2] = ‘e’;
data_name[3] = ‘s’;
data_name[4] = ‘t’;
Now when function returns back from dll:
-- modified at 9:48 Monday 18th September, 2006
|
|
|
|
|
Hi All,
I have a web application and I would like to download video files i.e. .flv or .wmv files from a web site, for example, youtube or google programmatically in my c# code. If you know how to do this please respond to this message. I appreciate your help. Thanks.
-- modified at 19:23 Thursday 14th September, 2006
|
|
|
|
|
Are you saying you want to offer video files to be viewed on your website, direct from your web servers hard drive? Or a way to retrieve video files from google video and YouTube to be used in your application some how?
Sunday Ironfoot
www.dominicpettifer.co.uk (work in progress)
|
|
|
|
|
Similar to something I posted a few messages up... you'll want to modify this to be a bit more asynchronous, especially if you're downloading large files like videos. This function downloads the contents of the web file and stores it in a temp file and returns the temp file name.
public string GetWebFile(string url)
{
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
Stream responseStream = null;
FileStream fileStream = null;
string filename = "";
try
{
webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webResponse = (HttpWebResponse)webRequest.GetResponse();
responseStream = webResponse.GetResponseStream();
filename = Path.GetTempFileName();
fileStream = new FileStream(filename, FileMode.Append);
int bytesRead = 0;
byte[] data = new byte[1000];
do
{
bytesRead = responseStream.Read(data, 0, 1000);
fileStream.Write(data, 0, bytesRead);
}
while (bytesRead > 0);
}
catch (Exception e)
{
MessageBox.Show("Error : " + e.Message);
}
finally
{
if (fileStream != null)
{
fileStream.Close();
fileStream.Dispose();
}
if (responseStream != null)
{
responseStream.Close();
responseStream.Dispose();
}
if (webResponse != null)
{
webResponse.Close();
}
}
return filename;
}
|
|
|
|
|
Hey
I have created a StreamWriter and an excel object and as far as I sew after creating the excel object part of the StreamWriter changed to null.
Did anyone had a similar issue ?
Clint
|
|
|
|
|
If memory is being stomped, it's being stomped by Excel in C++ and not by C#, per se. How does part of the object turn to null ? Which part ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The leak was in the object StreamWriter, BaseStream and Encoding became NULL.
Thanks,
Clint
|
|
|
|
|
|
How do I return Key-Value collection from a web service..
Is there any object I can make use of directly
Thanks
Jo
JO
|
|
|
|
|
Hi All,
I have a XML string with me in the format
<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SEQNO>6</SEQNO>
<B_CO_CD>H</B_CO_CD>
<B_AREA_CD>K</B_AREA_CD>
</row>
the XML tags are taken in an actual string variable and then I need to find a particular tag and get its value to actually set that value in a dataset column that corresponds to this tag.
How can I do this ??
Pls guide me.. I need to give demo on this..Pls Pls
Omkar
|
|
|
|
|
If I understood you correctly and you have a string variable that contains the given Xml, you could create a XmlDocument object and populate it with the Xml contained in the string using its Loadxml method. Afterwards use e.g. SelectSingleNode method to access the wanted data.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Is there a way that a method can get access to the name of the class that called the method?
Say I have a 'CoolConsoleApp' class that calls the 'DoStuff()' static method inside the 'MyUtils' class (MyUtils.DoStuff()), how could DoStuff() retrieve the class name 'CoolConsoleApp' at runtime? Cheers!
Sunday Ironfoot
www.dominicpettifer.co.uk (work in progress)
|
|
|
|
|
Take a look at the StackTrace class. It'll give you access to the StackFrame s your method was called by.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Sweet! That seems to have done the trick, for those interested I came up with the following code from mav's suggestions...
public static void StackFrameTest()
{
StackTrace trace = new StackTrace(true);
StackFrame frame = trace.GetFrame(1);
string x = frame.GetMethod().DeclaringType.Name;
}
Use a break point on string x and you'll see that x holds the class name of the method that called the StackFrameTest() method.
Sunday Ironfoot
www.dominicpettifer.co.uk (work in progress)
|
|
|
|
|
Hi All,
I have a problem with saving encrypted data into SQL 2000 server.
The user suppose to register with new password and the password
encrypted and save into DB. However, it "CONVERT" some chars into
"?" or "empty square ". Any idea?
Thanks
|
|
|
|
|
Those are characters whose values (unicode) are not mapped in your current display font. The actual binary data is unchanged, its just that the binary value doen't correspond to a legal character in the font set.
|
|
|
|