Witam próbuje przeexportowac z c na c# pisanie pyd, niestety wywala mi aplikacje gdzie użyje import metody. Moj kod
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Engine.Import;
[UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)]
public delegate int delegateRun(int arg,int arg2);
namespace Engine
{
internal static class UnmanagedExports
{
[DllExport("initfff")]
public static void initfff()
{
Py_InitModule("fff", HelloMethods);
// MessageBox.Show("ggggggg");
}
[StructLayout(LayoutKind.Sequential)]
public struct PyMethodDef
{
public PyMethodDef(string kml_name, int kml_meth, int kml_flags, string kml_doc)
{
ml_name = kml_name;
ml_meth = kml_meth;
ml_flags = kml_flags;
ml_doc = kml_doc;
}
[MarshalAs(UnmanagedType.LPStr, SizeConst = 30)]
public string ml_name; /* The name of the built-in function/method */
public int ml_meth; /* The C function that implements it */
public int ml_flags; /* Combination of METH_xxx flags, which mostly
describe the args expected by the C func */
[MarshalAs(UnmanagedType.LPStr, SizeConst = 30)]
public string ml_doc; /* The __doc__ attribute, or NULL */
};
[DllImport("python27.dll", SetLastError = true)]
public static extern int Py_InitModule(string name, PyMethodDef[] methods);
[DllImport("python27.dll", SetLastError = true)]
public static extern int PyCFunction_GetFunction(int arg);
public static PyMethodDef[] HelloMethods = new PyMethodDef[]
{
new PyMethodDef ("Method1", Marshal.GetFunctionPointerForDelegate(new delegateRun(Method1)).ToInt32(), 0x0001, "test")
};
public static int Method1(int self, int args)
{
MessageBox.Show("ffffff");
return 0;
}
}
}