|
Hi,
your code is rather mysterious:
- where is seconds declared and initialized?
- why are you including Thread.Sleep() in an event handler? that is generally a bad idea,
since it disables the normal event processing, and here I see no reason.
- anyway, Thread.Sleep(10) will NOT delay execution for 10 milliseconds; it will be anywhere
from 16 to much much more; you could read my timers article to learn more about it.
- if you want some code to run after 120 seconds have elapsed, why not just store the
time at the start of that period, then compare "now" with start+120 as in:
DateTime endTime=DateTime.MaxValue;
...
endTime=DateTime.Now.AddSeconds(120);
...
if (DateTime.Now >= endTime) {
endTime=DateTime.MaxValue;
...
}
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi!
I'm writing a C# application that is using some functions in a Visual Basic 6 ActiveX dll. The problem is that some of these functions use user-defined types as arguments. How can I call these functions?
I have tried creating a c# Struct that looks exactly like the Type in Visual Basic, but when I try to call the vb-dll-function with this struct as an argument, I get an error message that says something like: "Old format or invalid type library".
|
|
|
|
|
Those types must be public. Since they're COM objects, you should be able to create user-defined types in C#, even though they were defined in VB.
|
|
|
|
|
Hmm, ok...sounds good. Any clue how I can do that?
Simplified the VB6 ActiveX dll-code looks like this:
<br />
Public Type MyType<br />
Text As String<br />
Number As Integer<br />
End Type<br />
<br />
Public Function ShowMsgBox(Msg As MyType)<br />
MsgBox Msg.Text & VbCrLf & Msg.Number<br />
End Function<br />
Calling the function from C# I do like this:
<br />
Type COMType = Type.GetTypeFromProgID("MyDLLProject.MyDLLClass", true);<br />
object UnknownObject = Activator.CreateInstance(COMType);<br />
UnknownObject.GetType().InvokeMember("ShowMsgBox", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, UnknownObject, new object[] {XXXXXXXX});<br />
Where the XXXXXX is I really don't know what to put...
If it would have been ShowMsgBox(Msg As String), then no probs, I'd just put a string there, but now??
-- modified at 6:21 Monday 19th November, 2007
|
|
|
|
|
Instead of doing all this late-binding stuff, just add a reference in your project to your VB6 dll. Visual Studio will use the AxImp.exe tool in the .NET framework to generate a .NET-to-COM interop dll. From there, in C# you can use the types defined in the interop dll as if they were regular .NET types.
|
|
|
|
|
Thanks, sounds a bit easier that way, yes.
Problem is that I would prefer to have a late-binding since the dll won't always be present. It will work as a kind of a "plug-in" that some have and some haven't and I don't want to have to rebuild the whole app depending on which customer is going to have it. :-/
|
|
|
|
|
Have you looked up C# COM late binding? I just did a google search and found a good hit[^].
|
|
|
|
|
Well, I have. I feel like I've googled my brains out for this. All I've found is that it seems to be possible, but not HOW!
Thanks for the link it contains almost what I need, unfortunately it only shows how to pass an ordinary variable (a boolean). My dll requires a user-def type, question is how to "build" a similar type in c# (or how to convert a c# struct to a vb type maybe)?
|
|
|
|
|
I found an "intermediate" solution - to make another dll containing the user-def types (as these aren't changed that often) and add this as a reference in both the C# application and the Vb6 dll.
That way I can call the main dll with late binding, both c# and vb recognize the Type / Struct and I don't have to rebuild the app when I change the dll's functions. Until I decide to change the Types of cause...
It's not the ultimate solution, but I think it'll work.
Thank you for the help!
|
|
|
|
|
Hi All:
I want to create a program that have the ability to start sending & recieving information by bluetooth using c#, so please what are the basics steps I must do it before starting create this program.....
|
|
|
|
|
|
I would like to securely hide a connection string from anyone trying to break my C# assembly. I know I cannot just stick my connection string within my C# assembly because the use of Reflection would reveal it. Even through an Obfuscator the connection string can be somewhat hidden but not very securely. Putting the connection string in the app.config file and having Visual Studio automatically encrypt it is still not very secure in my eyes. I was thinking about storing it within a C++ unmanaged dll to prevent the use of reflection but I dont know if that is secure and also how do would I stop someone else from using that C++ unmanaged dll?
Has anyone found a good method out there that can be totally secure without using third party software and without using a web server?
Chris
|
|
|
|
|
|
For actual security you would need a password to be entered on application startup allowing you to use the System.Security.Cryptography namespace's cryptography classes.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
How to change the batch file icon to designed icon
naveen
|
|
|
|
|
you can only replace the icon for all batch files! a bat file can't contain any kind of resources.. bat files have only very limited features!
|
|
|
|
|
ok thanks,
How replace the icon for all batch files
naveen
|
|
|
|
|
open windows explorer - tools - folder options - file types.. select the file extension and press advanced - select icon.
|
|
|
|
|
You could create a shortcut to your batch file, and change the icon of the shortcut,
maybe that is sufficient for what you need.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
I want to send Mails via Mail Queue.
In ASP Email component, there is objsmpt.Queue option is available.
In .net how it will do????
please give idea regarding this
|
|
|
|
|
Will you please stop trying to bump your thread to the top of the queue? This is a volunteer forum and people will answer it when they are good and ready. Don't be so impatient.
|
|
|
|
|
May i know, who are giving this type of resposne?
i know this is volunteer forum. Then so what, i am asking different question always.
First of all see the question quality and strength.
No one should be free here to try to keep their name top of forum.
if u can u answer for this. Other wise keep quite. But dont give this type of reply.
Dont give this type of response again
|
|
|
|
|
You ARE asking the same question, you just re-worded it. Infact, you posted your first message, then because no-one had answered, you reposted it with slightly different wording three hours later under a different user name.
And now your asking it again.
If people know the asnwer, they will reply. There is no need to repost your question.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Hey - I'm one of the volunteers who wades through crap like this on a daily basis. More importantly because I do this regularly, when I see the same question appearing in a slightly reworded form, I tend to see if this person has posted this before.
Satish - Developer wrote: if u can u answer for this. Other wise keep quite. But dont give this type of reply.
Errmm. No. I gave you this answer to alert you to the rules we all follow for posting. Simply asking the same question in different ways does not qualify you as having asked different questions. It just says you've reworded your question to get it to the top and that's not fair on others.
Satish - Developer wrote: Dont give this type of response again
I would love it if I didn't have to do this. However, when people like you abuse the system like this, then I feel it my duty to inform you of what you have done wrong so that you respect others. Believe me, I would expect others to do the same to me if I had abused the system like this. Oh yes, and who am I to ask this question? I'm the guy who wrote the article[^] on posting questions in the forum.
|
|
|
|
|
Satish - Developer wrote: Other wise keep quite
Don't be so rude, please.
It has been explained to you where you broke the etiquette of the forum so I won't reiterated it. However, I will say that I agree with what has been said already.
|
|
|
|