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.
See this question you can't run a .NET dll using rundll32
Why don't you just create a simple console application which refers to the DLL as a class library?
Btw, I'd rename
smsSender
to something likeSmsSender
.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.
RunDll32 only works with DLLs specifically designed to be called from it. See http://support.microsoft.com/kb/164787 for more information.
The easiest way to run the code in that DLL from the command line would be to make a simple C# command line app whose sole purpose is to call that method.