|
DateTime.Now() returns current time
|
|
|
|
|
Giorgi Dalakishvili wrote: #region signature
my articles
#endregion
Very good!
I recognized that there was some confusion because of the articles link, but you really solfed it like a pro!
|
|
|
|
|
Martin# wrote: I recognized that there was some confusion because of the articles link
Thanks
Yes there have been several cases so I decided to solve it somehow. It would be cool if it had the same capabilities as in VS `
-- modified at 16:21 Tuesday 19th June, 2007
|
|
|
|
|
I don't want to look picky, but DateTime.Now is a property, not a method. In my newbie times, this would have confused me.
-----
Formerly MP(2)
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
Le Centriste wrote: I don't want to look picky, but DateTime.Now is a property, not a method. In my newbie times, this would have confused me.
Yes I have made mistake
|
|
|
|
|
Background: I am building a custom XML editor slash encryption tool.
I am having a problem dealing with multiple people accessing the same file (or a single person accessing the same file). What I am looking to do is if the file is currently open the user is prompted that the file is already open and only has read access.
Right now the user can open a file that is already open, then when either people with the same file go to save an error is thrown and the file is locked against any saving.
So my question is:
1)Is there a way to check if a file is already open?
2)If the file is open, the original person who opened keeps writing privilege well the other user is only given read access?
3)Can I prevent the file from being locked?
Thanks for the help.
|
|
|
|
|
When creating a new instance of FileStream class you can specify how other programs can access the file by FileShare enumeration
|
|
|
|
|
I will give that a try, thank you
|
|
|
|
|
I am getting an access error using this code:
try
{
m_oZipFile = new ZipFile(new FileStream(l_szLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.Read));
}
catch
{
m_oZipFile = new ZipFile(new FileStream(l_szLocation, FileMode.Open, FileAccess.Read, FileShare.Read));
}
|
|
|
|
|
What error are you getting?
|
|
|
|
|
The process cannot access the file 'C:\EncryptionTesting\DecryptInput\test-dispatch.config.rld' because it is being used by another process.
|
|
|
|
|
My guess is the Close() method was not called on a previous instance of the FileStream. From your sample code there is no reference to the FileStream.
|
|
|
|
|
The FileStream is called in the ZipFile call.
It seems to be sort of working now, what is mean is if I open 2 copies of the "Encryptor" tool the first one that access's the file always has read and write. The second one only gets read access, and never gets write access even after the first one is closed. From what I understand it should be given write access after the first one is closed. The code never actual gets into that catch statement as it does pass through the try statement.
|
|
|
|
|
This is my latest code:
try
{
m_oZipFile = new ZipFile(new FileStream(l_szLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.Read));
}
catch
{
MessageBox.Show("FILE IS ALREADY OPEN", "READ ACCESS ONLY", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
m_oZipFile = new ZipFile(new FileStream(l_szLocation, FileMode.Open, FileAccess.Read, FileShare.Read));
}
I am getting the following error:
The process cannot access the file 'C:\EncryptionTesting\DecryptInput\test-dispatch.config.rld' because it is being used by another process.
|
|
|
|
|
Your problem is probably in the second FileStream. FileShare.Read in the catch means that the first file stream (in the try) can have read access only.
<br />
catch<br />
{<br />
MessageBox.Show("FILE IS ALREADY OPEN", "READ ACCESS ONLY", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);<br />
m_oZipFile = new ZipFile(new FileStream(l_szLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));<br />
}<br />
|
|
|
|
|
Hi,every one,I have a problem in C# about calling dll writed by c, like the following,I can't get the correct answer.who can tell me why?
Here is the code about the dll's header file:
void _stdcall chuck(string);
void _stdcall wolfhome(string);
void _stdcall wolfsist(string);
void mein(char* directx11);
char* deme();
void inshuxiyin(char* directx11);
char* deshuxiyin();
char* _stdcall deshumil();
char* _stdcall shuredel();
char* _stdcall getDecryptStr();
void _stdcall wolfhomeseal(string);
void _stdcall wolfsistseal(string);
Here is the code about c#
[DllImport("bear.dll",CallingConvention=CallingConvention.StdCall)]
public static extern void chuck(string s);
[DllImport("bear.dll",CallingConvention=CallingConvention.StdCall)]
public static extern void wolfhomeseal(string s);
[DllImport("bear.dll")]
public static extern void wolfsistseal([MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bear.dll",CallingConvention=CallingConvention.StdCall)]
public static extern string deshumil();
[DllImport("bear.dll")]
public static extern string shuredel();
[DllImport("bear.dll")]
public static extern string getDecryptStr();
These are the methods I have tried,but none works fine,what problem exitsts?
Waiting for your answer,thanks!
|
|
|
|
|
|
Hi,
anuo06 wrote: none works fine
that is very specific !! is there anything that works ? works sometimes ?
how does it fail ? what crash, error, exception occurs ?
several suggestions:
1. apply CallingConvention to each prototype; you did only some
2. are you sure you need StdCall; it could also be Cdecl !
3. if any functions are available that take and return integers, get them
to work first, then solve the string problem.
4. if you own the C source, add logging code to both sides, and log every
call with arguments and return values.
|
|
|
|
|
Thank you for your answer first,but what I whrited is that I used several methods to achieve the result (this is the code I tried to find a good one, not the real code, in the real code ,I will use the uniform format), and all these dosen't work correctly.
When I use integer type , it works fine, just string and char*, when they convert to c# data type, I can't get the correct result.
A more stranger thing is that when I transmit parameter use "public static extern void chuck(string s);", such as the string "hello", it will get the input string "hello", it is correct!but when I use "public static extern void wolfhomeseal(string s);", and transmit a same (or others) string ,it will get a input as "?", always "?",what is that means?
All the problems are occured in type "string" and "char *" in c, the type "int" I tested is no problem.
|
|
|
|
|
OK,
consuming a C# string in C/C++ is somewhat easier than producing a
C# string in C/C++ code.
and there is the matter of 8bit ANSI versus 16bit Unicode and maybe other
encodings.
Normal steps are:
a string input (a char* in C) should be declared string in C#
a string return value should be declared string in C# (even it is char* in C)
a string output (as a parameter) should be declared a StringBuilder in C#
(and it must have sufficient Capacity !)
I suggest you pick one case and publish actual code for it, both the C# side
and the C/C++ side, plus you mention exact symptoms (show the first few characters
or bytes in hex on both sides of the P/Invoke border.
|
|
|
|
|
Hi,here is the c code of the two function:
void chuck(string s)
{
printf("string into chuck is:\n%s\n",s);
char d5[64] = {0};
int d2[64] = {0};
for(int i=0;i<64;i++)
{
d2[i] = (s[i>>3]>>(i&7)) & 1;
}
for(int j=0;j<8;j++)
for(int k=0;k<8;k++)
d5[8*j+k] = huwuwuan(d2[8*(j+1)-(k+1)]);
char a_1[56] = {0};
for(int k=0;k<56;k++)
{
a_1[k] = d5[d1[k]-1];
}
jiankzi(a_1);
}
void _stdcall wolfhome(string f3)
{
printf("string into wolfhome start is:%s\n",f3);
int strin = f3.length();
if(strin == 8)
{
athome(f3);
memcpy(mill,taime,16);
mill[16] = '\0';
}
else if(strin < 8)
{
f3 = feel(f3);
athome(f3);
memcpy(mill,taime,16);
mill[16] = '\0';
}
else if(strin > 8)
{
int strI = ceil(strin/8.0);
int strI3 = strin % 8;
string iS12;
for(int i=0;i
|
|
|
|
|
anuo06 wrote: void chuck(string s)
{
}
anuo06 wrote: void _stdcall wolfhome(string f3)
{
int strin = f3.length();
}
First of all this is not C code, it may be C++ code.
Is this code inside a .cpp file ?
Second an apparant difference between both functions is the absence/presence
of the _stdcall keyword.
You clearly have a problem with your calling conventions.
My advice is simple: choose an appropriate calling convention and
make it explicit EVERYWHERE, i.e. add CallingConvention=... to every C# prototype,
and a matching _stdcall/_Cdecl/whatever to every C/C++ function you plan to call
thru P/Invoke. Dont rely on defaults, they are rather complex, and may change
when you change compiler settings.
Which one (stdcall/Cdecl) you choose depends on circumstances. Read the documentation!
|
|
|
|
|
If I use c code like these,what is the correct calling code in C#?
void chuck(string);
char* deshumil();
The type "string" and the type "char*" are the main problems.
|
|
|
|
|
If I use c code like these,what is the correct calling code in C#?
void chuck(string);
char* deshumil();
The type "string" and the type "char*" are the main problems.
|
|
|
|
|
Hi all,
Here is the background to this issue. I am writing a C# program that is to be a self-guided training software. I have a sneaking suspicion that I'm not doing it properly.
Currently, I have several (10+) form screens. As the user goes through each form, there is a next button, which:
(1) Creates a new instance of next form (form2) & passes some parameters to form2
(2) from2.show
(3) this.dispose
I'm now running into a problem where there are certain cases where the user cancels out or needs to go back several forms (i.e. on form5, need to load form1) and an error occurs becuase I have disposed the form.
What is the proper way to do this? I think there are two other options that may be more correct, but I'm not sure which is right:
(a) Have all the controls for all the forms on one form. Pressing next causes a set of form controls to be visible and hides the controls not currently used. i.e:
* Main form has 4 sub-forms, each form containing a button form1, form2, form3 & form4.
* Initially form1 button is shown, all others hidden.
* Press next, and form1 button is hidden, form2 button is shown, all others hidden
* etc.
I think this may get cumbersome and messy.
(b) Have a main form and it'll contain child forms
(c) Have a main form and use it as a container for MDI
Any suggestions? Advice? Please correct me if I'm totally off track. Thank you so much!
~~~~~~~~~~~~
![Dead | X|](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_dead.gif) Over-worked, under-paid, glorified "secretary"
|
|
|
|
|