|
Sweet
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
Hi all,
Can anyone please explain how to add a binary file resource such as a wav, zip, avi, etc... to a .resources file BY CODE?
I've been searching msdn site for an answer but all the examples apply to Visual Studio .NET resource editors, as all programmers own and use it, right? And correct me if i'm wrong, Microsoft says that files can only be embeded directly to the assembly and not to .resources files.
I use notepad to write software and compile with batch files, so never think about suggesting me on using Visual Studio .NET resource editors.
Thanx man,
Heinz
|
|
|
|
|
I would look closely at the System.Resources.ResourceWriter class; I think it does everything you're looking for.
I actually used it one time when I wanted to embed some sound in a Windows app.
Something like the following would probably do the trick if you're just wanting to write binary resources to the file:
using System;
using System.IO;
using System.Resources;
using System.Runtime.Serialization.Formatters.Binary;
class ResourceUtility
{
public static void WriteResourceToFile(string name, object graph, string fileName)
{
BinaryFormatter serializer = new BinaryFormatter();
MemoryStream mem = new MemoryStream();
serializer.Serialize(mem, graph);
using (ResourceWriter writer = new ResourceWriter(fileName))
{
writer.AddResource(name, mem.GetBuffer());
writer.Generate();
writer.Close();
}
}
}
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi,
Thanx for your method. I use ResourceWriter in my programs to create resources and your method use it too so it's easy to understand how it works.
BUT, how do i call this function, i mean: If i want to add a .wav, a .zip or a .txt file, which parameter should i pass to the graph object?
For example: If i want to add an image i send the parameter 'Image.FromFile("C:\MyImage.jpg");' to the graph object.
If a want to add and icon i send the parameter 'new Icon(C:\MyIcon.ico);'
Thanx in advance.
|
|
|
|
|
If you have a file whose contents you want to add to a .resources file, use a FileStream to read the contents of the file, and the buffer from that stream as the source of the resource you're adding.
My example was just a generic example assuming you wanted to add a managed object as a resource.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi, thanx for your reply. I just want to add a .zip file for example, if i add this zip to a .resources with a visual editor like "Resourcer" or the sharpdevelop editor, you can see the object type, when i add the zip the type shown is System.Byte[] and this type is shown for all the binary files cause managed object shows as System.Drawing.Icon System.Drawing.Image System.String
I just want to add by code a non managed file so the type shows as System.Byte[]
I've tried all but never found how.
Thanx in advance
|
|
|
|
|
As I mentioned in my previous message, if you have a file you want to embed in a resource file, create a file stream using the target file, read the stream from start to end (will yield a byte array - type = byte[]), then use that byte array as the source of the resource entry. When you read the bytes back out of the resource, you can then use whatever kind of writer you want to "rehydrate" the bytes into a file, an image etc.
Here is an example of embedding a single .JPG image in a resource file - it's a trivial example, but it works and should get you started in the right direction:
public static void WriteResourceToFile(string importPath, string resourceKey, string resourceFileName)
{
byte[] buffer = null;
using (Stream file = new FileStream(importPath, FileMode.Open, FileAccess.Read))
{
buffer = new byte[file.Length];
file.Read(buffer, 0, (int)file.Length);
file.Close();
}
using (ResourceWriter writer = new ResourceWriter(resourceFileName))
{
writer.AddResource(resourceKey, buffer);
writer.Generate();
writer.Close();
}
}
The preceding function could be called to store an image file using:
ResourceUtility.WriteResourceToFile(@"c:\pic1.jpg", "pic1", "image.resources");
To read the image back out of the resource file, you could implement something like:
private System.Drawing.Image ReadImageResourceFromFile(string resourceFileName, object resourceKey)
{
MemoryStream stream = null;
Image i = null;
using (ResourceReader reader = new ResourceReader(resourceFileName))
{
IDictionaryEnumerator loop = reader.GetEnumerator();
while (loop.MoveNext())
{
if (loop.Key == resourceKey)
{
byte[] buffer = (byte[])loop.Value;
stream = new MemoryStream(buffer);
break;
}
}
reader.Close();
}
if (stream != null && stream.Length > 0)
{
stream.Position = 0;
i = Image.FromStream(stream);
stream.Close();
}
return i;
}
...and could be called using:
System.Drawing.Image result = ReadImageResourceFromFile("image.resources", "pic1");
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thanx man, it worked for me, thanx again for your help.
|
|
|
|
|
Respected Sir
Sir i am suffering from one problem and that is i
want to use a function s of a dll file in my c shap project this file is made up in vc++ .in .net frame work when i add a reference it donot allow to add the reference of this file kindly guide me in this regard.
Good Bye
Sajjad
From Sayed Sajjad Raza Zaidi
Itszaidi@hotmail.com
itssajjadraza@yahoo.com
|
|
|
|
|
P/Invoke allow you To use use unmanaged dll functions in your C# application P/Invoke was originally intended to provide access to the Windows API but you can use it to call function from any dll you need to use DLLImport attribute
and declare the method as a static extern
For example If you want to use FindWindow Function from user32.dll you will write somthing like
[DllImport("user32.dll", SetLastError = true)]<br />
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
Look at this article for more info
Calling Win32 DLLs in C# with P/Invoke[^]
MCAD
-- modified at 16:15 Sunday 4th September, 2005
|
|
|
|
|
hey all
i have a string '<cc1:CustomControl id="test" att1="some crap" att2="123"></cc1:CustomControl>'
this is valid xml so is it possible to put this into a node and get a collection of attributes?
|
|
|
|
|
Yes.
Just create an XmlDocument object and load the string into it with the LoadXml method. The node will be the root element, so you can get it using the DocumentElement property.
---
b { font-weight: normal; }
|
|
|
|
|
Dear All,
How can I marshall the following attributes in the following structure;
typedef struct IplImage
{.
.
struct _IplROI * roi;
void * imageid;
}
where _IplROI is itself a structure?
Another question is that the function unmanaged prototype is ;
IplImage * cvvLoadImage(const char * filename);
do I have to marshall the return type after defining the IplImage or I just write "IplImage *" after marshalling the structure??
Please Help,
Thanks and Best Regards,
E.A.
|
|
|
|
|
my problem this time is so complecated i ask God to can explain it
i need to make something like instance message betwwen two forms
i need to do the follwing
1- allow user in the first client to send message and save it in xmlfile then the other form or client recive it (something like the instance message in yahoo)
may i need to know more about threading so if there is any one can give mne link talk by simple way in threading i need it
|
|
|
|
|
Yahoo Messenger and the other instant messengers use a client-server model: basically, Yahoo has a server application running on some server machine that listens for connections from clients (the people running the instant messenger), then the server dispatches each message sent by a client to another client.
It's pretty easy to do this with .NET Remoting. .NET remoting allows you to call functions on other listening computers; what you need to do is search for .NET remoting. There are several .NET Remoting tutorials on CodeProject as well as on MSDN, including several "instant messenger"-like applications.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
hi all..
right now i'm working on the new project server monitor.
first brief intro.
i want to develop the application that will fetch the screenshot of the particular client connected with the server without disturbing he/she.
i have completed the get screenshot part of my project and how to store it as file.....
now main problem
how to know how many clients available and how to connect and how to receive the screenshot.....??
if anyone the please help me.....
|
|
|
|
|
You're going to need to write a windows service to deploy to the client to get the screenshot for you and send it your application. You can't just call up a Windows machine and grab the current screen. There's no built in service to do that (unless your clients are running XP that is,) so you have to write it yourself.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well!
i m having some trouble in writing this piece of code in c#. i m having some type conversion erros pls help me
specially the loop portion
Dim ids As Object
ScannerManager.EnumDeviceIDs(ids)
List.Items.Clear()
Dim i As Integer
For i = LBound(ids) To UBound(ids)
List.Items.Add(ids(i))
Next i
// signature and prototype information
'EnumDeviceIDs(ref Object)
returns array of strings that contain info
'public virtual new void EnumDeviceIDs ( System.Object IDs )
I M new in .net p
|
|
|
|
|
|
Hi
Its not clear from the code exactly what the EnumDeviceIDS method creates ids as, but i'll assume it is a .NET string array. In which case the code should be something like:
object ids = null;
ScannerManager.EnumDeviceIDs(ref ids);
string[] arrids = (string[])ids;
List.Items.Clear();
foreach(string id in arrids)
{
List.Items.Add(str);
}
Hope this helps
Philip
-- modified at 15:18 Saturday 3rd September, 2005
|
|
|
|
|
Problem is as follows:
got 100 PictureBoxes that are formed into 10x10 matrix. Their name is 'digit??', where '?' represents a single digit (digit00, digit01, ..., digit99). I would like to swiftly put all these PictureBoxes into one array. I tried:
PictureBox[,] References = new PictureBox[10,10];
...
for(int i=0;i<9;i++)
for(int j=0;j<9;j++)
{
this.References[i,j] = ((PictureBox)(String.Format("this.digits{0}{1}",i,j)));
}
which is of course not legal, as strings cannot be converted into PictureBoxes. I know it may be done using the Reflection Emit, but I`m looking for another way. Any hints?
-- modified at 13:08 Saturday 3rd September, 2005
|
|
|
|
|
It doesn't really make sense to me to create 100 picture boxes and then set an array to reference these 100 picture boxes. Why don't you use an array object to create the 100 picture boxes in the first place? Since you have a 10x10 matrix of them, there will be a mathematical formula for creating the pictureboxes. Just use a for loop and create all 100 picture boxes, so that they will be easily accessible. If the problem is that each box contains a specific image file, you should label all the images with the same scheme..ie: img00.bmp, img01.bmp...etc. I've used this approach when designing little quick games.
|
|
|
|
|
Is there anyway to have a program notified of time change events in Windows? For example if I wanted to be notifed when the hour changed...is this possible?
Thanks
- Aaron
|
|
|
|
|
There's a timer control. You give it a number of milliseconds, and when that time interval has passed it throws an event that you can receive. To receive a message every hour just set the interval to 3600000 milliseconds.
|
|
|
|
|
hi,
i have a problem when i send a HttpRequest!
first i send a request to get the session_id than a login request and after that a other request....
after that i begin with the request for session_id and than the problem arise when i send the login request...
i get a timeout error when i call request.GetRequestStream (); by why!?!
cu
<br />
request for session id:<br />
-----------------------<br />
HttpWebRequest get_request = (HttpWebRequest)WebRequest.Create("https://www.myzone.at/webkeeper/Controller");<br />
get_request.CookieContainer = new CookieContainer();<br />
<br />
HttpWebResponse get_response = (HttpWebResponse) get_request.GetResponse();<br />
get_response.Cookies = get_request.CookieContainer.GetCookies(get_request.RequestUri);<br />
<br />
String sessionid = "Cookie: ";<br />
sessionid += get_response.Cookies[0].ToString();<br />
<br />
login request:<br />
--------------<br />
HttpRequestResponse login_request = new HttpRequestResponse("https://www.myzone.at/webkeeper/Controller", "POST", "action=login&login=Anmelden&brand=myzone&username=xxxxxx&password=xxxxxxb&x=83&y=13");<br />
login_request.SESSION_ID = sessionid;<br />
login_request.SendRequest();<br />
<br />
<br />
<br />
sendrequest method:<br />
-----------------------------------------<br />
public string SendRequest()<br />
{<br />
string responseFromServer="";<br />
<br />
try<br />
{<br />
if((RequestMethod.ToUpper() != "GET") && (RequestMethod.ToUpper() != "POST"))<br />
throw new WebException(RequestMethod+ " is not a valid method. Use GET or POST.");<br />
<br />
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL);<br />
request.Method = RequestMethod;<br />
request.Headers.Add(SessionId);<br />
<br />
if(RequestMethod.ToUpper()=="POST") <br />
{<br />
byte[] byteArray = Encoding.UTF8.GetBytes (PostData);<br />
<br />
request.ContentType = "application/x-www-form-urlencoded";<br />
<br />
request.ContentLength = byteArray.Length;<br />
<br />
Stream requestStream = request.GetRequestStream (); <------------ here arise the timeout when i send the 2nd login request...<br />
<br />
requestStream.Write (byteArray, 0, byteArray.Length);<br />
requestStream.Close ();<br />
}<br />
<br />
HttpWebResponse response = (HttpWebResponse) request.GetResponse();<br />
Stream dataStream = response.GetResponseStream ();<br />
StreamReader reader = new StreamReader (dataStream);<br />
responseFromServer = "HTTP/" + response.ProtocolVersion + " " + response.StatusDescription + " ";<br />
responseFromServer += response.Headers.ToString();<br />
<br />
reader.Close ();<br />
dataStream.Close ();<br />
response.Close ();<br />
}<br />
<br />
catch (WebException e)<br />
{<br />
throw CatchHttpExceptions(responseFromServer = e.Message);<br />
}<br />
catch (Exception e)<br />
{<br />
throw new Exception(responseFromServer = e.Message);<br />
}<br />
<br />
return responseFromServer;<br />
}<br />
|
|
|
|