On Thu, Oct 31, 2013 at 9:50 AM, Pavel Korotkov <...> wrote:
>
> Well, I've got two AllocConsole wrappers:
>
> package main
>
> /*
> #define _WIN32_WINNT 0x0502
> #include <windows.h>
> */
> import "C"
>
> ...
>
> func AttachConsoleToParentProcess1_WINAPI() error {
> funName := "AttachConsole"
>
> r, err := C.AttachConsole(C.ATTACH_PARENT_PROCESS)
> if r == 0 {
> return fmt.Errorf(funName+"'s return flag is FALSE; Last error: %s", err.Error())
> }
> return nil
> }
>
> func AttachConsoleToParentProcess2_WINAPI() error {
> funName := "AttachConsole"
> fun, err := kernel32.FindProc(funName)
> if err != nil {
> return err
> }
>
> var app uint32 = 0xFFFFFFFF // Constant ATTACH_PARENT_PROCESS as stated in MSDN: (DWORD)-1
> r, _, lastErr := fun.Call(uintptr(unsafe.Pointer(&app)))
> if r == 0 {
> return fmt.Errorf(funName+"'s return flag is FALSE; Last error: %s", lastErr.Error())
> }
>
> return nil
> }
>
> When I try to attach a console back to the parent process (main.go:55), only AttachConsoleToParentProcess1_WINAPI does the job. AttachConsoleToParentProcess2_WINAPI doesn't work on my machines. That's it. What else can I do?
>
> PS: Since I use Win7/Win8.1 one can omit '#define _WIN32_WINNT 0x0502' directive on top of the file.
>
I am sorry, but I don't understand what "does the job" and "doesn't work" means. Perhaps, if you can give us a program, and then tell us what you see when the program runs, and then tell us what you think is wrong with the output you see and why. Thank you.
Alex