|
Hello
In C# you can't access ports -and other devices as well- directly using FileStream. I don't know why they didn't add this support though!! If you do it throws System.NotSupportedException with this message:
"FileStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr. "
Now just like the message said, to access divice in C# as files do the following:
1- Use P/Invoke to call Win32 API function called CreateFile with the name of the device -in your case it will be @"\\Computername\Printer Share Name"
2- Retreive the handle to the device from the above function
3- Give that handle to one of the FileStream constructors overlosds that takes Argument 1 as a IntPtr
4- Now you have a FileStream object and you can access the device as a file
Regards
|
|
|
|
|
thanks for the quick reply
thats exactly the error message i got, after a bit of research I found a small tutorial on how to do this but didnt manage to successfully get it to work. I could well have done somehing completely wrong though (ive ben using c# for about 2 weeks so far so alot of this is quite daunting).
I shall endevour to give this another go when i get back to work.
thanks again
edd
|
|
|
|
|
Edd,
Is the tutorial you found online? I too need to access a printer with C# and am very new to C#.
Thanks,
Carol
|
|
|
|
|
|
|
Does anyone know how to create an application that will work on a computer that does not have the .Net Framework installed? It keeps saying that it can't find the mscoree.dll file. Is there any way of puting it into the program so you dont need to install .Net Framework?
|
|
|
|
|
Hello
Sorry!! Not possible.
C# like any other .Net language was made for the .Net framework, and your C# apps won't work unless the .net framework was installed on the user's machine.
Anyway, you can include .Net framework in your deployment project as a prerequisite, and then the .Net framework will be installed on the user's machine with your application in a quiet mode -ie. the user won't know-.
Otherwise you will have to migrate your app to old fashioned C++.
Regards
|
|
|
|
|
Hi
I wrote a script in Visual Basic that selected an area in photoshop by the following script:
selRegion = Array(Array (0,0),Array(60,0),Array(60,60),Array(0,60),Array(0,0))
docRefNewPicture.Selection.Select(selRegion)
Now I want to implement this code in a C# project. I already wrote a script that opens the picture but now I wanted to select the area by the following code:
NewPicture.Selection.Select(selRegion,1,0,false);
In this code selRegion must contain the information about the area I want to select, but I have no idée how to define the area and in what kind of object or format. I already tried the following tinks:
int[,] selRegion=new int[,] {{0,0},{60,0},{60,60},{0,60},{0,0}};
(error only one dimensional arrays)
System.Drawing.Rectangle Rect=new System.Drawing.Rectangle(0,0,60,60);
System.Drawing.Region selRegion=new System.Drawing.Region(Rect);
(error array expected)
Can anybody help me how to define selRegion??
Tanks a lot
Bauke
BWT
|
|
|
|
|
Hello
Your question is well organized but lacks some details.
Bauke Tilma wrote: I already wrote a script that opens the picture
Never heard of C# script?!! How do you open the picture exactly?? In photoshop, Component, or in your form?!!
Bauke Tilma wrote: NewPicture.Selection.Select(selRegion,1,0,false);
What is the type on NewPicture?
Bauke Tilma wrote: error only one dimensional arrays
Where is the prototype -ie. declaration- of the method that takes the selected area dimensions?
Regards
|
|
|
|
|
Is it possible to merge some columns as it is in microsoft word?
Thanks in advance
|
|
|
|
|
Hello
If you want to merge Column2 into column1
1- Read the data of each cell in column2
2- Append the data to each cell in column1
3- resize column1 to fit the data
4- remove column2
Regards
|
|
|
|
|
How can i change the current resulation of window when program is start ??
With Thanks
MHF
|
|
|
|
|
Hello
I don't think this is possible in C# per se. You have to call API functions.
Here is an Article[^] about it.
Regards
|
|
|
|
|
I am designing a report that requires that, for each page, the sum of a specified column is to be displayed at the end of the column before going on to the next page. For each page the total displayed should be sum of the column values on that page.
There is also a requirement that the same total at the end of the page be displayed at the top of the next page.
How do I achieve this?
example:
------Page 1------------
previous page total: 0
chq_amt
100.25
50.25
58.50
20.75
20.25
current page total: 250
----Page2--------
previous page total: 250
chq_amt
10.50
18.25
100.75
20.50
50.00
current page total: 200
etc.
This is my sign
|
|
|
|
|
Hi,
I have just added a tooltip component to a form and after I set a tooltip text, whenever I close the form I keep getting an "Object not set to an instance of an object" error message on closing the form.
protected override void Dispose(bool disposing)<br />
{<br />
if (disposing && (components != null))<br />
{<br />
components.Dispose();<br />
}<br />
base.Dispose(disposing); < --- "Object not set to an instance of object" error here<br />
}
Here's the code that I use to close the form :-
private void buttonFinished_Click(object sender, EventArgs e)<br />
{<br />
Dispose();<br />
this.Close();<br />
}
This only occurs if I set the text for a tooltip. If I don't set any text no error is thrown.
What gives? - Any ideas
Glen Harvy
|
|
|
|
|
Just a small idea :
If you dispose your form when you press the Finishedbutton, then all the stuff in your form gets disposed
But after that you call the Close method. As far as i can see, the closemethod closes the form and releases all, by calling Dispose(bool).
Try to compile/run your code without the dispose.
I have never tried to call a dispose method inside the form that I want to close, I have always Disposed it outside of the form (many times I do not dispose it at all and just reset the form to reuse it a few moments later when the user wants to see it, what is very likely).
Don't you also love the code?
|
|
|
|
|
Thanks for making it all seem logical .
Getting rid of dispose does fix it of course.
As an aside, when would one expicitly call dispose in a program?
Glen Harvy
|
|
|
|
|
|
Hi,
My scenario is as follows:
I spawn mukltiple threads simultaneously and all threads invoke functions simultaneously. These functions are in a single threaded application. What happens if one thread invokes the function and before it completes its processing, another thread also invoke it? Will both the threads execute the function simultaneously or will one thread complete its operation and only then the other will start processing?.
In my case I want one specific function to be executed synchronously. Only one thread should execute it at a time because it makes use of certain resources whic can be used by only one thread at a time. How to lock the entire method?
Can
lock(this)
{
//Code goes here...
}
be used in this scenario.
It would be better if any of you are able to suggest a solution for this.
Thanks and Regards
Madhu
|
|
|
|
|
Hello
Forget the crap I said in my last post. I told you my mind was crashed back then.
Anyway, here is the right thing. Two Approaches: Note: x is your object
1- Use the lock statement:
lock(x)
{
DoSomething();
}
2- Use the
System.Object obj = (System.Object)x;
System.Threading.Monitor.Enter(obj);
try
{
DoSomething();
}
finally
{
System.Threading.Monitor.Exit(obj);
}
The above codes are quoted from MSDN.
I think you already got that by now, but I want to post that just in case you didn't.
Regards
|
|
|
|
|
Hie,
i need to know how to enumerate all pcs.. connected locally to the users computer.. also i need to display this information in a treeview.. .. i need to show the workgroups and the pcs in them....and also list all the mapped drives .... i have C# 2005 .. .NET 2.0 so i'll need to know how to do it with System.Net(i think.. i jst started C#)
would someone give me a WELL COMMENTED example code.. or perhaps a link to an article or tutorial??
i got no answer on the MSDN forums so PLEASE HELP
Thanx
Gideon
|
|
|
|
|
Hello
giddy_guitarist wrote: i jst started C#
Just started C# and you want to map a network?!! Did you try MSDN library -not the forums-
Anyway, most of what you need is in the System.Net.NetworkInformation namespace, especially IPGlobalProperties class. Look them up in your MSDN documentations.
giddy_guitarist wrote: would someone give me a WELL COMMENTED example code
Try the examples of MSDN in the above classes. If you're stuck with something, we are here.
Regards
|
|
|
|
|
|
hey.. listen.. i did extensive readin on System.Net
IPGlobalProperties-> Provides information about the network connectivity of the local computer. .. i want to enum. neworks remember... AND i found some code that claims to enum. networks with System.DirectoryServices... .BUT i dont understand any of the code cuz... well its not commented at ALL!
it was originally in VB.NET... i got someone to port it to C# .. but the problme is i CAN:T check if it works on my PC!!.. cuz i dont hav networks.. COULD SOMEONE PLEASE TELL ME IF THE FOLLOWING CODE WORKS!/?
<br />
private void btnList_Click(object sender, EventArgs e) <br />
{<br />
DirectoryEntry entryRoot = new DirectoryEntry("WinNT://" + this.tbComputerName.Text.ToUpper(), "", "", AuthenticationTypes.None);<br />
<br />
DirectoryEntries memberEntries = entryRoot.Children;<br />
<br />
this.lvUsersGroups.SmallImageList = this.ImageList1;<br />
foreach (DirectoryEntry member in memberEntries)<br />
{<br />
if(member.SchemaClassName.Equals("User"))<br />
this.lvUsersGroups.Items.Add(member.Name, 0);<br />
<br />
if(member.SchemaClassName.Equals("Group"))<br />
this.lvUsersGroups.Items.Add(member.Name, 1);<br />
} <br />
}<br />
<br />
You will, of course, need to wire up btnList's Click event to call the above handler if you haven't already done so:<br />
<br />
this.btnList.Click += new System.EventHandler(this.btnList_Click);
heres where i got the original code - > http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3213&lngWId=10[^]
PLEASE TELL ME IF EITHER ONE DOES THE JOB?
Thanx
Gideon
|
|
|
|
|
Hello
Easy Tiger!!
Well, yes it works, and shows my shared network printer if supplied with the computer name that's connected to the printer. Well done!!
I thought you wanted to enumerate connected PCs. What this code does is to enumerate shared folders on a Pc name that you supply!! What good is that for you? Otherwise from where do you get the this.tbComputerName ??
As for the network problem. If you don't have more that one computer, you can download Microsoft's Virtual PC 2004 for free, and make a virtual network between your machine and the "Virtual PCs". This way you can test and modify you code step by step on your "Virtual network". Google for "Microsoft Virtual PC".
Regards
|
|
|
|