in Education by
I want to execute HelloWorldConsole.exe with an shipped Mono Framework through Go. So I want to call mono-2.0-sgen.dll funtion "mono_main" to execute the exe. mono-2.0-sgen.dll is a PE32 executable for MS Windows, see. But I get the error "not a valid Win32 application" _ = os.Setenv("MONO_PATH", `\mono\lib\mono\4.5;C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\Debug`) _ = os.Setenv("MONO_CFG_DIR", `"C:\Program Files (x86)\Mono\etc"`) _ = os.Setenv("MONO_CONFIG", `"C:\Program Files (x86)\Mono\etc\mono\config"`) mono := `C:\Program Files (x86)\Mono\bin\mono-2.0-sgen.dll` app := `C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\Debug\HelloWorldConsole.exe` fmt.Println("Execute") var mod = syscall.NewLazyDLL(mono) var proc = mod.NewProc("mono_main") ret, _, _ := proc.Call(0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("mono.exe"))), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(app))) ) Same behavior with windows.NewLazySystemDLL dll := windows.NewLazySystemDLL(mono) lazyProc := dll.NewProc("mono_main") lazyProc.Call() Function Name Full Error: panic: Failed to load C:\Program Files (x86)\Mono\bin\mono-2.0-sgen.dll: %1 is **not a valid Win32 application**. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
%1 is not a valid Win32 application The error %1 is not a valid Win32 application is a discription of Win32 error code from windows itself. The Win32 error code itself is 0x000000C1 ERROR_BAD_EXE_FORMAT, see docs.microsoft.com. BAD_EXE_FORMATmeans you call a x86 dll within a x64 process. You must use the x86 variant of Go, e.g. go1.12.1.windows-386.zip from https://golang.org/dl/. Now must change the GOROOT and PATH to the extracted bin folder and then you are ready to go. Type of Arguments When you call mono_main you need to consume the this function in the right way. If you take an look at the implementation you see that the signature is int mono_main (int argc, char* argv[]);. argc and argv is a widly used pattern, see here. Working Sample func main() { _ = os.Setenv("MONO_PATH", `C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\x86\Debug\mono\lib\mono\4.5;C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\x86\Debug\`) _ = os.Setenv("MONO_CFG_DIR", `C:\DEV\HelloWorhpm.goldConsole\HelloWorldConsole\bin\x86\Debug\mono\etc`) _ = os.Setenv("MONO_CONFIG", `C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\x86\Debug\mono\etc\mono\config`) _ = os.Chdir(`C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\x86\Debug\`) mono := `C:\DEV\HelloWorldConsole\HelloWorldConsole\bin\x86\Debug\mono\bin\mono-2.0-sgen.dll` // https://github.com/mono/mono/blob/c5b88ec4f323f2bdb7c7d0a595ece28dae66579c/mcs/tools/mkbundle/template_main.c#L1 dll := windows.NewLazySystemDLL(mono) lazyProc := dll.NewProc("mono_main") dotNetAssembly := []byte(`HelloWorldConsole.exe`) var argumentData [260]byte ptr := unsafe.Pointer(&argumentData) copy(argumentData[:], dotNetAssembly) args := [2]uintptr{0, uintptr(ptr)} _, _, _ = lazyProc.Call(2, uintptr(unsafe.Pointer(&args))) }

Related questions

0 votes
    What is the most idiomatic way to handle multiple errors in go? Should I try to wrap the error ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I've created a library as the module for personal use outside of "GOPATH" in "database" folder with ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    Is it possible to get model's table name? I see that it's possible to get it from ModelStruct ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I would like to call a .net 4.0 dll from an IIS7 application that is running in a .net 2.0 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    In an election between two candidates, one got 55% of the total valid votes, 20% of the votes were invalid. If the total number of ... got, was : A) 2500 B) 2700 C) 2900 D) 3100...
asked Feb 14, 2021 in Education by JackTerrance
0 votes
    is it possible to call c# methods written in managed code (maybe in a class or a library) from a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    What will happen if we call setTimeout() with a time of 0 ms? (a) Placed in stack (b) Placed ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Explain the statement - We have got this Earth planet on lease from our future generations and ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 8, 2021 in Education by JackTerrance
0 votes
    I see many user interface control libraries for .NET, but where can I get similar stuff for win32 using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    How many messages does the queue for a standard window hold? What happens when the queue overflows? The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    What are the steps and techniques to debug an apparent hang due to a deadlock in a Win32 production process ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    How can I mock the database calls to make my application logic been tested without database? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    How can I mock the database calls to make my application logic been tested without database? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    How can I mock the database calls to make my application logic been tested without database? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    How can I mock the database calls to make my application logic been tested without database? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
...