Hello,
I need to convert the C code, that reads a DLL generated from Matlab/Simulink:
#embrace <home windows.h>
void important() {
// varieties
void (*mdl_initialize)(void); // perform
double* mdl_G; // worth
// Dll load
void* dll = LoadLibrary("./teste_win64.dll");
// GetProcAddress
mdl_initialize = (void(*)(void))GetProcAddress(dll , "initialize");
mdl_G = ((double*)GetProcAddress(dll, "G"));
// Run initialize and seize the G worth
mdl_initialize();
printf("G = %.2f",*mdl_G);
}
to Golang.
I simply tried this tip:
func important() {
dll, _ := syscall.LoadDLL("./teste_win64.dll")
mdl_init, _ := syscall.GetProcAddress(dll.Deal with, "initialize")
mdl_G, _ := syscall.GetProcAddress(dll.Deal with, "G")
real_init := (*func())(unsafe.Pointer(&mdl_G))
real_G := (*float64)(unsafe.Pointer(&mdl_G))
real_init()
log.Print(*real_G)
}
However no success. Any tip?
From WindowsDLLs · golang/go Wiki · GitHub it appears to be like such as you want uintptr
as an alternative of unsefe.Pointer
and syscall
as an alternative of attempting to transform the pointer to a *func
.
I had success utilizing NewLazyDll and NewProc:
dll := syscall.NewLazyDLL("teste_win64.dll")
mdl_G := dll.NewProc("G")
G := (*float64)(unsafe.Pointer(mdl_G.Addr()))
However VSCode report that unsafe.Pointer(mdl_G.Addr()) is misuse. There`s a greater kind to do that?
1 Like
This implies you possibly can’t work with the pointers from syscall with out go vet falsely complaining about it.
1 Like