|
Hi,
I am sending data in the form of a COPYDATASTRUCT to a second application using the SendMessageTimeout() API function. The data is sent accordingly and the COPYDATASTRUCT retrieved at the other end using Marshal.PtrToStructure. I would now like to pass back a new COPYDATASTRUCT in the Message.Result, I do this with the following:
<br />
Win32.COPYDATASTRUCT cds = new Win32.COPYDATASTRUCT();<br />
cds.dwData = 1;<br />
cds.lpData = mydata;<br />
cds.cbData = Win32.GlobalSize(cds.lpData);<br />
<br />
IntPtr pResult = Marshal.AllocCoTaskMem(Marshal.SizeOf(cds));<br />
Marshal.StructureToPtr(cds, pResult, true);<br />
m.Result = pResult;<br />
Now the correct IntPtr value is passed back in the result param of the SendMessageTimeout function but when I try to retrieve the structure using Marshal.PtrToStructure() all 3 members of the strucure are zero.
I'm sure I'm missing something obvious here but I've been staring at it for hours and can't seem to see the problem.
|
|
|
|
|
I'm guessing you are sending a WM_COPYDATA message (with your COPYDATASTRUCT) to the other application. In general, Windows keeps each application in it's own virtual memory space. This virtual memory space is completely independent of other applications. So if you allocate memory in application#1, then the pointer returned is only good for application#1.
If you look at the MSDN[^] documentation for WM_COPYDATA, the first line under Remarks states that "The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data". Because pointers are only valid for the given application. You can pass the memory location (a.k.a. the pointer's value) to another application, but the other application cannot do anything with it.
To copy data back, you would have to send a WM_COPYDATA message back to the first application. You could also use named pipes[^], .Net remoting, or maybe this[^].
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi to all,
I am trying to delete all the files in a specified folder in my project. for that i have written the following function....
==============================================================================
Code
==============================================================================
public void DeleteTempFiles()
{
DirectoryInfo DirInfo = new DirectoryInfo(Server.MapPath("~/temp/"));
if(DirInfo.Exists)
{
foreach (FileInfo FI in DirInfo.GetFiles())
{
FI.Delete();
}
}
}
==============================================================================
But whenever i am running the program it gives the error as....
Error Deleting File or Folder
Cannot delete <filename>: It is being used by another person or program.
Close any program that might be using the file and try again.
.....
Anybody help me to solve this problem.
Pravin
|
|
|
|
|
It means that the file you want to delete is in use either by your program or by other programs. If your program has an open handle to the file then close it.
|
|
|
|
|
Hy,
Try using this code
string[] files = Directory.GetFiles(Server.MapPath("~/temp/"));
foreach (string s in files)
{
File.Delete(s);
}
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
That will still suffer from same problem with files in use, or not?
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
It won't suffer any problem, because the application doesn't open the file, that's why I used the static methods of the Directory and File classes.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Nope, original code that enumerates over temp files and tries to delete them didn't open any files as well. That's not the problem. Problem is that OTHER parts of application, or other applications keep the file opened. File.Delete does pretty much the same work as FileInfo.Delete (both check permissions and then call Win32Native.DeleteFile, just look with Reflector).
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Andrei Ungureanu wrote: It won't suffer any problem, because the application doesn't open the file
It may not open the file, but it will still fail if some other process has a handle to that file. Specifically, it will throw an IOException.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Depending on what's running on your system, the temp directory will pretty much always have files that can't be deleted because an application has created te file and still has a handle to it. The only thing that you can realistically do here is to try/catch the file delete and continue with the processing as appropriate.
public void DeleteTempFiles()
{
DirectoryInfo DirInfo = new DirectoryInfo(Server.MapPath("~/temp/"));
if(DirInfo.Exists)
{
foreach (FileInfo FI in DirInfo.GetFiles())
{
try
{
FI.Delete();
}
catch (IOException ioex)
{
}
catch (Exception ex)
{
}
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Is it your own temp folder, or the system one? If it shared (system one) you can't really avoid this, and you can do what Pete said... if it's your own temp, you are probably forgeting to close some file - which is something you should fix. You can see who is locking the file with ProcessExplorer[^]
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
What about acess rights of the folder being deleted?
|
|
|
|
|
Wouldn't error message be different?
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
I certainly would.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I want to realize the following:
During one loop, a status form window is displayed, it is closed when the loop is done. but I want to stop the loop before the loop finishes. I have one button on the status form to be clicked to stop. but no response when I click it. How to do it?
thanks!
|
|
|
|
|
Hello,
You have to call "Application.DoEvents()" inside the loop.
All the best,
Martin
|
|
|
|
|
Hi, Martin,
thanks a lot. It does work.
However, I met another problem.
when I click the button to stop the loop, the firt click does not work, that means I have to click two times, after that, then it work perfect.
further I found that I have to click the form window first then I can handle this window, or else I can not. I tried to use Activate() and Focus(), neither works, Could you please give me one hint for that?
thanks a lot.
|
|
|
|
|
well, you must have some condition inside your loop, you have to "and" that condition with a boolean flag which is set when the cancel button is clicked.
eg
bool cancel = false;<br />
<br />
while(yourCondition && !cancel)<br />
{<br />
}
Then your cancel button would just set that cancel variable to true. You will need to do your loop within another thread in order to keep the form responsive.
|
|
|
|
|
when my program login server how to choose the right server(CHINA TELECOM or China Netcom ...) and how to choose the nearest server?
|
|
|
|
|
I am using SqlCommandBuilder to update data in DataSet to DB and I got a problem is:
DataSet includes 2 tables : 1 is Master and the other is Detail
1. When user adds new row in DataTable => This record must be insert into Master table first, and then it will be inserted
into Detail Table.
2. When user delete data in DataTable => This record must be deleted in Detail Table first, and then it will be deleted
in Master Table.
User can add new, edit or delete data in DataTables until they click Save button => Update data in DB.
Please help me how can I do this with SqlCommandBuilder.
Thanks a lot.
pvphuc
|
|
|
|
|
Hi all!
I want information on , how to integrate resumegrabber software with .net OR is there any way to merge database of resumegrabber with sql server database.
Regards,
Amol G.
|
|
|
|
|
In C#.net windows application
in design view i am just placing the datagridview control
in form load event i am dynamically defining the columns and then adding rows so every time there is an extra row is coming and one column is image column so extra row displaying the image "x".
In order to avoid this extra row what should I do
Please help me
Praveen Kumar Palla
|
|
|
|
|
Set the AllowUsersToAddRows property of the DataGridView to False
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Andrei
Thank you very much
It is very useful to me.
|
|
|
|
|