Giter Site home page Giter Site logo

godll's People

Contributors

z505 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godll's Issues

DLL with parameters

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);
| ^~~~~~~~

Return **C.Char

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

Issue in calling a function from DLL in GO Lang

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.