Hi all,
I want to use Run("someProgram.exe")
command using BASIC language. This will open the 3rd application program.
If that program running using .dll(not sure if it possible) not .exe, how can i code that?
thanks in advance.
Hi all,
I want to use Run("someProgram.exe")
command using BASIC language. This will open the 3rd application program.
If that program running using .dll(not sure if it possible) not .exe, how can i code that?
thanks in advance.
If you want to execute a DLL function from the command line, use: Rundll.exe
Note that your exported function is required to match exactly the (C) signature:
void CALLBACK EntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);
If it does not, it is undefined as to what will happen, but you will probably crash. The normal routine for calling arbitrary functions from dlls in class VB is to use the Declare statement. You must know the signature of the function you want to call at compile time.
For example:
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
Function GetUser()
Dim RetVal As Integer
Dim UserName As String
Dim Buffer As String
Buffer = New String(CChar(" "), 25)
RetVal = GetUserName(Buffer, 25)
UserName = Strings.Left(Buffer, InStr(Buffer, Chr(0)) - 1)
MsgBox(UserName)
End Function
This code calls the "GetUserNameA" function from advapi32.dll. There are many sites devoted to listing the Declare
syntax for arbitrary windows functions, so it is not typically difficult to find the correct one.
Its hard to answer without understanding the nature of your .dll. Of course, there is no way to simply pop your dll into some harness and expect it to just run. It would have to be an exe for that. You could create your own shell/wrapper exe that simply acts as a process host with an entry point and then fires methods on the dll.
I'm not sure if this would fit your model but if you were in the position where you can require these dlls contain a class that implements an interface. Say IRunnable that contains a single Run() method. You could create an exe that that receives the dll as a command line argument, uses reflection to find IRunnable and then loads that class and calls Run().