z505 / godll Goto Github PK
View Code? Open in Web Editor NEWhow to create windows golang DLL and load into C, or delphi, or freepascal
how to create windows golang DLL and load into C, or delphi, or freepascal
Can you show example of import PrintHello function?
When try to export as in godll.c
PrintHello(GoString p1);
goDLL.c: In function 'dummy':
goDLL.c:6:13: error: expected expression before 'GoString'
6 | PrintHello(GoString p1);
| ^~~~~~~~
Been trying to return a string, not printing it to console, but there seem not to be a way.
I did try 2 different approaches
//export PrintHello2
func PrintHello2(Input *C.char, Output **C.char) int32 {
*Output = C.CString(fmt.Sprintf("From DLL: Hello, %s!\n", C.GoString(Input)))
return 1
}
and
//export PrintHello4
func PrintHello4(Input *C.char) *C.char{
return C.CString(fmt.Sprintf("From DLL: Hello, %s!\n", C.GoString(Input)))
}
I'm calling this code from .net using the following test code
class Program
{
[DllImport("goDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int PrintHello2([In] byte[] data, [MarshalAs(UnmanagedType.I1)] ref SByte[] output);
[DllImport("goDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern SByte[] PrintHello4(byte[] data);
static void Main(string[] args)
{
string res = "demo";
SByte[] output= { };
Console.WriteLine("PrintHello4 Returns: " + PrintHello4(Encoding.UTF8.GetBytes(res)).Length);
Console.WriteLine("PrintHello2 Returns: " + PrintHello2(Encoding.UTF8.GetBytes(res), ref output));
Console.WriteLine("Ref Val changed to: " + output.Length + "\n");
}
}
None of the Go function works as expected and program chashes with System.Runtime.InteropServices.MarshalDirectiveException for any of the 2 functions
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 main
import (
"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 S3")
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.