|
it returns error code 2 - ERROR_FILE_NOT_FOUND
|
|
|
|
|
You might want to try Sysinternals' Process Explorer. It can enumerate every kernel object (that includes pipes) that exists inside a process. This way you could be sure the pipe name is being created the way you intend.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
thank you.
I have Process Explorer but I don't know how to see list of objects for a process.
I used the search option to search for "mypipe". It shows that the server has a handle to \Device\NamedPipe\pipe\mypipe . I tried to check the client to open "\Device\NamedPipe\pipe\mypipe" but that didn't help (I didn't expect it to work anyway).
|
|
|
|
|
This is how the client opens the pipe:
hPipe=CreateFile("\\.\pipe\mypipe",
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL) ;
if ( hPipe!=INVALID_HANDLE_VALUE)
{
return 0;
}
err = GetLastError();
if(err!=ERROR_PIPE_BUSY)
{
printf("Could not open pipe, GetLastError=%u\n", err);
return -1 ;
}
Create file returns an invalid handle. GetLastError() returns 2.
|
|
|
|
|
You do know that backslashes need to be escaped in C++, right? It should be:
hPipe=CreateFile("\\\\.\\pipe\\mypipe",
GENERIC_WRITE, 0,
NULL,
OPEN_EXISTING,
0,
NULL) ;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes i do for some reason the codeproject shows just 1 backslash. I do have it like this:
"\\\\.\\pipe\\mypipe"
|
|
|
|
|
Let's see the code that creates the pipes in both projects.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Server: C#
NamedPipeServerStream pipeServer = new NamedPipeServerStream("\\\\.\\pipe\\mypipe", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);
Client: C++
hPipe=CreateFile("\\\\.\\pipe\\mypipe",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL) ;
if ( hPipe!=INVALID_HANDLE_VALUE)
{
return 0;
}
err = GetLastError();
if(err!=ERROR_PIPE_BUSY)
{
printf("Could not open pipe, GetLastError=%u\n", err);
return -1 ;
}
printf("Could not open pipe, GetLastError=%u. WaitNamedPipe.\n", err);
if(! WaitNamedPipe(pipe_name,2000))
{
printf("Could not open pipe\n");
return -1 ;
}
again:
C++ client with C++ server - works.
C# client with C# server - works.
C++ client with C# server - does not works.
Thank you.
|
|
|
|
|
This is just a guess, but could it be that since you have specified both GENERIC_READ and GENERIC_WRITE for the client, then you need to open the server as "InOut"?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I thought of that. I tried changing the server side to InOut - it did not help.
i also tried changing the client to GENERIC_WRITE without GENERIC_READ - it didn't work either.
Thank you for all the advise, tips and time you spent trying to help - much appreciated.
|
|
|
|
|
I think the problem was found....
On stackoverflow, someone posted this answer:
C#'s NamedPipeClientStream, NamedPipeServerStream automatically append ".\pipe\" to the name
I changed the C# code to open the pipe just as "mypipe" and now the connection is successful.
|
|
|
|
|
Glad you got it sorted.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hello,
How to read and print *.plt file by C#?
Thank you!
|
|
|
|
|
There are several interesting articles on how to do this here[^]. The assumption is that you are automating AutoCAD from .NET. If you are attempting to do this without AutoCAD, you're going to have to find a component that reads and understands AutoCAD files.
This space for rent
|
|
|
|
|
Overview
I'm working on this class to asynchronously copy files to/from the server. I want to run it in tasks so that I can copy many files at one time without blocking.
I've pieced this class together from Google results and trial and error. It does two things for me:
1) Reports the progress of the copy
2) Reports when it's done.
The FileEx class I got from here[^].
Questions
1) How can I include the name of the file in the progress?
2) How can I include the name of the file when done?
Here's the class:
using System;
using System.Threading.Tasks;
using MyApp.FileTransfer;
using MyApp.Client.Classes;
namespace MyApp.Client.FileTransfer
{
public class LANFileTransfer : IFileTransfer
{
#region Public Methods
public async void DownloadFile(string sourceFile, string destFile)
{
await Task.Run(async () =>
{
await TransferFile(sourceFile, destFile);
}).ContinueWith((t) => FileTransferComplete(t));
}
#endregion
#region Private Methods
private void FileTransferComplete(Task task)
{
}
private void FileTransferProgress(double percentage)
{
}
private async Task TransferFile(string sourceFile, string destFile)
{
IProgress<double> progress = new Progress<double>(FileTransferProgress);
await FileEx.CopyAsync(sourceFile, destFile, progress);
}
#endregion
}
}
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
1st thought ... the CopyFileEx routine has a lpData input that is passed to the callback function(s?) - could you pass a pointer to the string filename here ?
(there's also a nice article on wrapping CreateFileEx here .NET Reference Guide | .NET Book Recommendations | InformIT[^] that you may get some mileage out of - I note Jim calls this pointer 'UserData')
2nd thought .. not sure Im going to use the correct terminology .. 'daisy chain the callbacks' - the first CreateFileEx (or whatever) callback calls an Internal to your class callback-handler - you then from this handler call your 'external' handler from here adding any other information you want
3rd thought - Im certifiable
|
|
|
|
|
Your DownloadFile method looks off to me. Calling Task.Run just to await the result doesn't really achieve anything.
It would be cleaner to use Task.Yield to force the rest of the method to execute in the continuation.
You should also return a Task so that the calling method can wait for the transfers to complete.
Avoid async void methods - You've Been Haacked[^]
To pass the file names to the progress method, you just need to capture them in the progress callback.
public async Task DownloadFile(string sourceFile, string destFile)
{
await Task.Yield();
await TransferFile(sourceFile, destFile);
FileTransferComplete(sourceFile, destFile);
}
private async Task TransferFile(string sourceFile, string destFile)
{
Action<double> reportProgress = percentage => FileTransferProgress(sourceFile, destFile, percentage);
IProgress<double> progress = new Progress<double>(reportProgress);
await FileEx.CopyAsync(sourceFile, destFile, progress);
}
private void FileTransferProgress(string sourceFile, string destFile, double percentage)
{
}
private void FileTransferComplete(string sourceFile, string destFile)
{
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you
If it's not broken, fix it until it is
|
|
|
|
|
As you might surmise, you report progress back with an instance of IProgress. When you created it, you limited it to being a double - why not create a structure that encapsulates the double and the filename, and pass this across instead? Then, when you are reporting the progress back, you would need to report progress using this structure instead of just the double.
This space for rent
|
|
|
|
|
Nice idea. Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Hi can you please help me, with main problem. I am try create own menu for disabled peoples. Here is code:
PictureBox pb = new PictureBox();
int pbCounter = 0;
int pbWidth = 100;
int pbHeight = 100;
void MainFormLoad(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(@"otherapp\");
foreach (FileInfo f in dir.GetFiles("*.exe"))
{
pbWidth = pbWidth+10;
pbCounter++;
pb.Location = new Point(pbWidth,pbHeight);
pb.Width = 100; pb.Height = 100;
pb.BackColor = Color.AliceBlue;
pb.Name =Convert.ToString(f);
pb.BackgroundImageLayout = ImageLayout.Stretch;
pb.MouseEnter += new System.EventHandler(PicBox);
}
}
void PicBox(object sender, EventArgs e)
{
}
This create last icon for exe files Screenshots:
[img]http:\\88.86.108.112\1.png[/img]
Files is directory
[img]http:\\88.86.108.112\2.png[/img]
Main probem
[img]http:\\88.86.108.112\3.png[/img]
This i want have.
When i have 5 exe files is directory otherapp\ create 5 icon on "dekstop" with names of exec files. And when i am click on icon on "desktop" executet this software.
Thx
|
|
|
|
|
What is your question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Right click the icon on the desktop.
Click Properties.
Click Shortcut.
Click "Change Icon..."
|
|
|
|
|
I have three pages
page 1 :through a submit button in page 1 ...
I want to be redirected in page2 in new tab and page3 in the same tab.
Is that possible?
Page1 contains :
using (MemoryStream memoryStream = new MemoryStream())
{
document.Save(memoryStream, false);
memoryStream.Position = 0;
Session["BinaryData"] = memoryStream.ToArray();
ScriptManager.RegisterStartupScript(this, this.GetType(), "openPDF", "javascript:window.open('../../Service/Pages/Page2.aspx');", true);
Response.Redirect('../../Service/Pages/Page3.aspx');
}
page2: to be opened in a new tab
protected void Page_Load(object sender, EventArgs e)
{
if (Session["BinaryData"] != null)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=" + filename);
Response.BinaryWrite((byte[])Session["BinaryData"]);
}
then page 3:
will be redirected in the same tab
Thanks in advance
|
|
|
|
|
Start by taking out the javascript: protocol from your script registration:
ScriptManager.RegisterStartupScript(this, this.GetType(), "openPDF", "window.open('../../Service/Pages/Page2.aspx');", true);
That should get rid of the script error.
You'll then see a warning from the popup blocker in your browser, since your script is trying to open a new window, and it's not in direct response to the user clicking something on the page.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|