Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to run a c# dll from the command line

Tags:

c#

rundll32

I have a c# dll defined like this:

namespace SMSNotificationDll
{
    public class smsSender
    {
        public void SendMessage(String number, String message)
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "c:\\Program Files\\Java\\jdk1.6.0_24\\bin\\java";
            info.WorkingDirectory = "c:\\";
            info.Arguments = "-jar SendSms.jar "+number + " "+message;
            info.UseShellExecute = false;
            Process.Start(info);
        }
    }
}

and i need to execute it from the commandline.

Is there any way I can run it through rundll32?

When I run it with this :

rundll32 SMSNotificationDll.dll, SendMessage 0749965244 hello

I get missing entry: SendMessage.

like image 472
Nico Avatar asked May 26 '11 12:05

Nico


People also ask

Do I need to run my air conditioner?

Related Story. It may seem like a waste of energy to turn your A/C on and off, but doing so actually saves you a fair amount of money, Amann says. "Air-conditioning systems run most efficiently when they're running at full speed," she explains.

How often should AC run?

Ideally, a properly operating air conditioner should cycle for roughly 15 to 20 minutes, two to three times per hour. If the temperature inside your home is very high, is much higher than the temperature that your thermostat is set at, or the outside temperature is very high, the run time will increase.

How many hours should an AC run per day?

Example: If the temperature day highs are in the 90s and the lows in the high 70s, you should run an AC for about 8 hours per day. The daily temperature should be about 75°F during the day and about 72°F during the night.


2 Answers

See this question you can't run a .NET dll using rundll32

like image 98
Emond Avatar answered Sep 20 '22 16:09

Emond


There is a trick to create unmanaged exports from c# too - https://www.nuget.org/packages/UnmanagedExports

How does it work? Create a new classlibrary or proceed with an existing one. Then add the UnmanagedExports Nuget package. This is pretty much all setup that is required. Now you can write any kind of static method, decorate it with [DllExport] and use it from native code. It works just like DllImport, so you can customize the marshalling of parameters/result with MarshalAsAttribute. During compilation, the task will modify the IL to add the required exports.

class Test
{
  [DllExport("add", CallingConvention = CallingConvention.Cdecl)]
  public static int TestExport(int left, int right)
  {
     return left + right;
  } 
}
like image 33
Nick Bilak Avatar answered Sep 19 '22 16:09

Nick Bilak