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
Issue in calling a function from DLL in GO Lang #40890
Comments
What did you see on your computer when you ran this program? |
Setup : Visual Studio Code ( Windows 10) Debug Console Output API server listening at: 127.0.0.1:22699 goroutine 1 [running]: |
Check the error here, dll is nil |
Hi Yes, Right dll is nil. |
if you check |
It goes into syscall_windows.go |
Is A1.dll file in the same directory as your program? Alex |
Yes Both are present on the Desktop. |
Please add this line fmt.Println(err) After this line dll, err := syscall.LoadDLL("A1.dll") And paste the result |
API server listening at: 127.0.0.1:32073 Note: I changed the Dll name ( A1 -> Dll2) I wrote the Dll code using C++ in Visual Studio 2017 and Configuration is as follows : |
API server listening at: 127.0.0.1:32073 I wrote the Dll code using C++ in Visual Studio 2017 and Configuration is as follows : |
Googling this error message suggests that there is a mismatch between the architecture that your dll is compiled with and the version of Go you are using. Would you please complete the issue template so we can investigate further. Thank you https://github.com/golang/go/blob/master/.github/ISSUE_TEMPLATE |
Hi, |
Thank you for confirming you've been able to fix the problem. As to your other questions, unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For asking questions, see:
|
Problem Description : There is dll( A1.dll- compiled in C++) in which a function is defined as
EXPORT void S3(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow){}
A1.dll
`// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include
//#include
#define EXPORT extern "C" __declspec(dllexport)
EXPORT void S3(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
MessageBox(NULL, TEXT("Hello World"),
TEXT("In a DLL"), MB_OK);
}
**I want to load this DLL using GO lang. For this I am writing below program:**
package mainimport (
"fmt"
"syscall"
"golang.org/x/sys/windows"
)
func main() {
dll, err := syscall.LoadDLL("A1.dll")
proc, err := dll.FindProc("S3")
_, _, dllError := proc.Call()
fmt.Println("calling TestPP")
fmt.Printf("Error, err: %s\n", dllError)
fmt.Printf("Error, err: %s\n", err)
}`
This is not working. Also I am not able to understand that here how to pass the parameter in call function according to function S3 definition. Could anybody help me in understanding this issue?
The text was updated successfully, but these errors were encountered: