|
Sorry I was out of town.I have tried it but
It didnt work. Dont know why.
Do I need to use any event handler code to the .Designer.CS page?
Like this.grid1.keypress += new .....
pls make it clear.
Thanks again
modified on Saturday, April 18, 2009 11:24 AM
|
|
|
|
|
Hi
I have 2 Windows Service Question
1.Is WS can work in background ? Is it posible to do some job evry 2 minutes ? (if yes, can I get some help ?)
2.How can I install WS in simple way ? (not with Installutil.exe .......)
3.How to run .exe file through WS
i'll do this:
System.Diagnostics.Process G = new Process();
G.StartInfo.FileName = @"d:\demo.exe";
G.Start();
thank's in advance
|
|
|
|
|
1. Yes, absolutely. Use the System.Threading.Timer class. Read the documentation for the choices that are offered to you.
2. Installutil.exe is the best way. You may try to use a setup project instead, but I never tried it.
3. This seems to be correct to me.
E_Gold wrote: I have 2 Windows Service Question
You should learn how to count, that was 3 questions.
|
|
|
|
|
1) Yes. Avoid the Timer class and write a threaded timer.
2) You can't not use installutil.exe...
3) Use the Process class.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I use a System.Timers.Timer
|
|
|
|
|
You get more control with a thread, and the timer events are the lowest priority events in Windows. This means that on a busy system, your app might not even *see* the event. Personally, I take no chances with that kind of stuff.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Well then it depends on usage; the Timer does what I need it to.
|
|
|
|
|
This[^] article looks like a viable alternative
I are troll
|
|
|
|
|
1) Yes, but are you sure you don't want a Windows Scheduled Task?
2) Kinda sorta, as the article pointed out by Eddy suggests. That's how I do it.
3) Yes, but are you sure you don't want a Windows Scheduled Task?
|
|
|
|
|
Hi all,
I'm having a problem using DllImport in C# to call a C++ function.
C++ Header File:
DLLEXPORT int drawMarkupOnLine (int jobId, int lineNumber, short* line, int drawMode);
C++ Source File:
DLLEXPORT int drawMarkupOnLine (int jobId, int lineNumber, short* line, int drawMode)
{
...
}
==========================================
C# Source File:
[DllImport("vdrdll.dll", EntryPoint = @"?drawMarkupOnLine@@YAHHHPAFH@Z")]
unsafe static extern int drawMarkupOnLine(int jobId, int lineNumber, short* line, int drawMode);
...
short* scan0 = (short*)bmd.Scan0;
short* nextScanLine = scan0;
drawMarkupOnLine (0, i, nextScanLine, lca[i]);
==========================================
When I try to call the function, I get an EntryPointNotFoundException, with message, "Unable to find an entry point named '?drawMarkupOnLine@@YAHHHPAFH@Z' in DLL 'vdrdll.dll'."
I've tried various permutations of IntPtr, string pointers, and void pointers for the third parameter (which I'm assuming is causing the problem), but nothing seems to work. (Other functions with only int parameters work just fine.) Can someone suggest a reliable way to get this to link?
Thanks,
Alan
|
|
|
|
|
Hi Alan,
in C# one does not need unsafe nor short*, instead ref short would do.
since native C++ is mangling names, I suggest you try DllImport("vdrdll.dll", EntryPoint="...", ExactSpelling=true) , since maybe the marshaling is adding an A or W because of the pointer.
|
|
|
|
|
Thanks for the suggestion Luc, but I'm still getting the same result. It even happens when I use a simple local variable for the 3rd parameter.
|
|
|
|
|
It gets stranger: The problem still shows up even with all int parameters.
|
|
|
|
|
OK, I suggest you use DUMPBIN or some other tool to verify the symbols exported by your DLL file.
BTW: you are not getting confused (or confusing your tools) by having several copies of the DLL in different places, other folders, GAC, ...?
FWIW: I tend to use C, not C++, for native code, avoiding all name mangling. Never had such problems.
|
|
|
|
|
Thanks Luc. I got the symbol from the VdrDll.exp file (exports library file), which seems to work for the other exported functions.
I tried renaming the generated DLL, and got the expected missing module error message.
Yes, C would be simpler, but I'm trying to leverage a massive existing code base already in C++.
|
|
|
|
|
Hi Alan,
I did some experiments using VS2008 Express for both C++ and C# and all went well, here is the relevant code:
#define NATIVECPPEXPERIMENT_API __declspec(dllexport)
NATIVECPPEXPERIMENT_API int fint1(int arg1) {
return arg1*arg1;
}
NATIVECPPEXPERIMENT_API int fint4(int arg1,int arg2, short* arg3, int arg4) {
*arg3=(short)(arg1*arg2);
return arg1*arg4;
}
namespace ConsoleApplication1 {
class Program {
static void log(string s) {Console.WriteLine(s);}
static void Main(string[] args) {
int res1=cppfint1(12);
log("res1="+res1);
short shrt=14;
int res4=cppfint4(12,13,ref shrt, 15);
log("res4="+res4);
log("shrt="+shrt);
Console.ReadLine();
}
[DllImport("nativeCppExperiment.dll", EntryPoint="?fint1@@YAHH@Z")]
static extern int cppfint1(int arg1);
[DllImport("nativeCppExperiment.dll", EntryPoint="?fint4@@YAHHHPAFH@Z")]
static extern int cppfint4(int agr1, int arg2, ref short arg3, int arg4);
}
}
So either you are overlooking something, or your system is ill. I suggest you try closing and reopening Studio, and consider rebooting.
|
|
|
|
|
Thanks again for the help Luc! Your code looks perfect. This is what I tried to do with the ref parameter.
I've been experimenting, and taking out the EntryPoint clause allowed the linker to find the function:
[DllImport("vdrdll.dll")]
static unsafe extern void drawMarkupOnLine(int jobId, int lineNumber, short* line, int drawMode);
I don't understand why this worked. Now I'm getting a read/write-protected-memory exception, but this may just be a "normal" bug.
|
|
|
|
|
Alan Balkany wrote: taking out the EntryPoint clause allowed the linker to find the function
That is amazing, if not impossible. I've never read that should work.
I tried it for my second call, and I immediately got an EntryPointNotFoundException, as I was expecting.
namespace ConsoleApplication1 {
class Program {
static void log(string s) {Console.WriteLine(s);}
static void Main(string[] args) {
int res1=cppfint1(12);
log("res1="+res1);
short shrt=14;
int res4=fint4(12,13,ref shrt, 15);
log("res4="+res4);
log("shrt="+shrt);
Console.ReadLine();
}
[DllImport("nativeCppExperiment.dll", EntryPoint="?fint1@@YAHH@Z")]
static extern int cppfint1(int arg1);
[DllImport("nativeCppExperiment.dll")]
static extern int fint4(int agr1, int arg2, ref short arg3, int arg4);
}
}
Your system is acting weird if you ask me.
|
|
|
|
|
I took your advice and restarted the system, and did a Rebuild Solution on both halves. The results were the same; it links perfectly with the Entry Point left out for only that function.
"Your system is acting weird if you ask me."
I blame Microsoft.
|
|
|
|
|
|
could it be you have a C-version of that function somewhere?
or a hidden extern "C" { ... } around it?
|
|
|
|
|
Neither of those are present. (Looking around, I can see you've been busy today!)
Thanks again for the help!
|
|
|
|
|
No problem.
|
|
|
|
|
How do I access the data coming in and out of the USB Port on a PDA using C#. My PDA is not a host, but I should still be able to communicate with a Host. I do not want to use the Active Sync. Any help and code snippets would be greatly appreciated.
|
|
|
|
|
You can use SerialPort class or this library for communicating directly with Usb port: LibUsbDotNet[^]
|
|
|
|
|