Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write a dynamic link library file? #121

Open
nowayout opened this issue Sep 2, 2021 · 0 comments
Open

How to write a dynamic link library file? #121

nowayout opened this issue Sep 2, 2021 · 0 comments

Comments

@nowayout
Copy link

nowayout commented Sep 2, 2021

I am preparing to write a dynamic link library file,it contains a winform. The code such as:

`
func init() {
title := "Spark"
hInst := win.GetModuleHandle(nil)
if hInst == 0 {
panic(fmt.Sprintf("GetModuleHandle: %v", win.GetLastError()))
}

wc := win.WNDCLASSEX{}
wc.CbSize = uint32(unsafe.Sizeof(wc))
wc.LpfnWndProc = syscall.NewCallback(wndProc)
wc.HInstance = hInst
wc.HbrBackground = win.COLOR_WINDOW + 1
wc.LpszClassName = syscall.StringToUTF16Ptr(title)
wc.Style = win.CS_HREDRAW | win.CS_VREDRAW
if atom := win.RegisterClassEx(&wc); atom == 0 {
	panic(fmt.Sprintf("RegisterClassEx: %v", win.GetLastError()))
}

hwnd = win.CreateWindowEx(
	win.WS_EX_TOOLWINDOW,
	syscall.StringToUTF16Ptr(title),
	syscall.StringToUTF16Ptr(title),
	win.WS_VISIBLE | win.WS_POPUP,
	0,
	0,
	0,
	0,
	0,
	0,
	hInst,
	nil,
)
if hwnd == 0 {
	panic(fmt.Sprintf("CreateWindowEx: %v", win.GetLastError()))
}

win.ShowWindow(hwnd, win.SW_HIDE)
win.UpdateWindow(hwnd)

var msg win.MSG
for {
	if m := win.GetMessage(&msg, 0, 0, 0); m != 0 {
		win.TranslateMessage(&msg)
		win.DispatchMessage(&msg)
	}
}

}

func wndProc(hwnd win.HWND, msg uint32, wparam, lparam uintptr) (result uintptr) {
switch msg {
case win.WM_DESTROY:
win.PostQuitMessage(0)
case win.WM_DEVICECHANGE:
OnDeviceChange(hwnd, msg, wparam, lparam)
case WM_USB_EVENT: // Customer Message
OnUsbEvent(hwnd, msg, wparam, lparam)
default:
return win.DefWindowProc(hwnd, msg, wparam, lparam)
}
return 0
}

//export DoPausePlay
func DoPausePlay() *C.char {
doPause()

return C.CString("0")

}
`

But when another program calls, it hangs at this code:

for { if m := win.GetMessage(&msg, 0, 0, 0); m != 0 { win.TranslateMessage(&msg) win.DispatchMessage(&msg) } }
Other methods, such as DoPausePlay(), cannot be called. How can I change this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant