|
Hi,
there are many ways you can pass data to a thread, and retrieve results.
For one, there is a possibility to pass an object to Thread.Start(); so you could store all the inputs in that object before you start the thread, and/or retrieve all the results once the thread is done.
Or you could turn that around, and have a little class (say class Job), which you instantiate, pass parameters (thru properties maybe), then call its Run method (which launches a thread inside that class, invisible to the outside world), and finally gets the results available somehow (e.g. again as Properties). This is my preferred way; it makes it very easy to run several similar jobs at the same time, just by instatiating more Job objects and Run()ning them.
|
|
|
|
|
You can use the class BackGroundWorker and handle the completed event and getting the property "Result" of the event args
Saludos!!
____Juan
|
|
|
|
|
I want to create a key to my application. When installed at client for the first time it should install. If the client want to install again it should not install.And if the client want to copy the setup file it should not be copied to any other location.
|
|
|
|
|
Unless your application "phones home" to a license server on your end, there's no way to stop this from happening. A client will be able to install your app as many times as they want.
|
|
|
|
|
Hey
I want to inject DLL made in C# into an Application.
Ive been looking for this for a long time, but still cant find the answer.
In C you would use it like this
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
MessageBox(0, "Test", "Test", MB_OK);
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
Is there a way to do this in C#? Like when I inject it, that it also shows the MessageBox at successfull injection?
Thanks in Advance
- opx
|
|
|
|
|
LoadLibrary[^] will call DllMain for you, so you can use P/Invoke for that task.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you for your kind reply, but I still dont get it.
Im not really familiar with LoadLibrary...
This is what I got so far
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MyDll
{
public class clsMain
{
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string lpFileName);
}
}
|
|
|
|
|
So did you actually call the method?
LoadLibrary("YourDll.dll");
if this returns some value != IntPtr.Zero then the call was successful.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you
You see, im using a program called Winject to inject the dll. I guess that really does it all.
When it gets injected, it automatically calls the LibMain function and executes the code in my Dll.
But when I try to inject the dll I made in c#, it doesnt get executed, this is the code im using:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MyDll
{
public class clsMain
{
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("user32.dll")]
public static extern int MessageBox(int hwnd, string lpText, string lpTitle, int style);
public void LibMain(IntPtr hInstance, int fdwReason, int reserved)
{
MessageBox(0, "Injected from C#", "C# hello world", 0);
}
}
}
Thank you very much again!
- opx
|
|
|
|
|
I'm confused, do you have a native DLL or a .NET DLL? First, you presented a native DLL, now you're showing me the code of a .NET DLL, which works totally different and where LoadLibrary has no effect on.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I wanted to make a Dll like c but in c#, so yes a native Dll.
I want it to be injected into a process, and not called.
But I guess C# is not really a good language for this, right?
Thanks for your replies
- opx
|
|
|
|
|
OptiPlex wrote: I want it to be injected into a process, and not called.
I'd rather use a native DLL, then.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
If you want to inject your DLL code into another process, which you do not control, your .DLL MUST be written in a non-managed language (non-.NET). That means that you cannot use C# to write the .DLL. .DLL injection only works with native-code, not managed.
|
|
|
|
|
Okay, I got the answer for my question now. Thank you all!
|
|
|
|
|
|
hello guys,
I am a beginner.I am interesting in Aforge.net.It is a really fantanstic framework~!
I want to know how to use AForge.net in C# to connect to a Camera.I found the Motion_Detection article but it's too diffcult to me.I can not to understand it.~_~;
So what I want to know is just a very simple example to show how to connect to a camera and get a image from the camera. Thanks~!
I am really really really really eager to know the answer asap.
MSN:franva008@hotmail.com
now this is my code:
private void button1_Click(object sender, EventArgs e)
{
// enumerate video devices
AForge.Video.DirectShow.FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
// create video source
VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
//VideoCaptureDevice videoSource = new VideoCaptureDevice("Acer HD Crystal Eye webcam");
// set NewFrame event handler
videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
// start the video source
videoSource.DesiredFrameRate = 25;
videoSource.DesiredFrameSize = new Size(pictureBox1.Width, pictureBox1.Height);
videoSource.Start( );
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// get new frame
//Bitmap bitmap = eventArgs.Frame;
pictureBox1.Image = (Image)((object)bitmap);
//pictureBox1.Image = (Image)eventArgs.Frame;
// process the frame
}
Error message:invalue Parameters
modified on Saturday, December 13, 2008 11:31 AM
|
|
|
|
|
HI,
In My application I need to retrive the excution file for a given mimetype.
i.e.
I have "Smaple.doc" So I retrive it's MimeType by "doc" extention and now I'm missing the way to
retrive the actual excution file of the mimeType (in this example it should be "winword.exe".
Any ideas on how to do so?
it doesn't have to be the same way I'm thinking of doing it, as long as the in string is a given file name ("xxx.doc") and out is the excution file ("winword.exe").
tnx
modified on Saturday, December 13, 2008 6:19 AM
|
|
|
|
|
Are you sure you need to know the exe?
if you execute Process.Start("xxx.doc") it will launch whatever exe is associated with the .doc extension (probably winword.exe), as if you double-clicked the file in Windows Explorer.
|
|
|
|
|
Hello,
As Luc has told you if the only thing you need is to launch the application associated with doc file, you can use Process class. On the other hand if you really need to retrieve application path then you will need to use various methods for reading windows registry as the information is stored in system registry.
|
|
|
|
|
Anyhow I found the answer my self already.
It's all in the registry.
in order to retrive which application is associated with the extention you need to access the OpenWithList key for the extention.
all the extentions are located under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
there you can find your extention and all you need is to open the OpenWithList key
i.e.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.doc\OpenWithList
in this key you will find DWORD's a,b,c
each represent and application to use in order to open this file.
"a" is the default.
|
|
|
|
|
I want to store Controls(All Buttons) of my form in array list.Is it possible.
|
|
|
|
|
Use generic collection, it's better. But you can use ArrayList as well but remember that ArrayList stores type Object so when you are retrieving you have to cast them.
List list = new List();
|
|
|
|
|
Hi,
you can store anything you like in an ArrayList or any other kind of collection (Hashtable, SortedList, ...).
you can store all kinds of objects with a common base type (such as Control) in a List of that type, or any other kind of collection capable of holding your base type (Dictionary, ...).
You probably don't have to create a new collection since each Control (and hence each Form) already has a collection holding ALL its Controls.
Example: if you want to do something to all the Buttons on myForm, this would be sufficient:
foreach(Control c in myForm.Controls) {
Button btn=c as Button;
if (btn!=null) {
btn.PerformClick();
}
}
Warning: a foreach on an enumerator will not allow you to modify the collection, so the above loop would not allow you to add or remove buttons; you would need a for or while loop for that.
|
|
|
|
|
|
Don't forget that the form also may have containers (panels, group boxes etc) which may have buttons in them. You will need a recursive structure to get ALL the buttons on a form.
Never underestimate the power of human stupidity
RAH
|
|
|
|