3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
961 stars 133 forks source link

Confused. What to use? (exported structure variable) #27

Open c0nnex opened 7 years ago

c0nnex commented 7 years ago

I am exporting some functions using DLLExport which is working great. But I also need to export a Variable (Pointer to a FunctionPointer-Structure), which will be set from the native application loading my assembly and I then want to call a function in that struct from within my managed code.

So what i want to do basically (simpilfied):

[DLLExport] FuncPtrStruct EXPORTVAR;

public double GetExternalValue(Int32 index) { if (EXPORTVAR == null) return -1; return EXPORTVAR->get_nativedata(index); }

where get_indexdata would be defined as "double (__stdcall *get_indexdata) (int index)" in the struct

So what else apart from DLLExport will I need, or would it maybe easier to write a native dll that provides the exported variable, handles the calls to it and loads my managed assembly, communicating with it through exported functions?

Hints welcome.

3F commented 7 years ago

` >_< it hard to understand what you do, and what you want at all, but I think I understand what you need

amm.., firstly about exported-variables:

that is, DllExport works via ILAsm that currently contains logic (part of mscorpe) for prepare exported-functions only. I will look this task later. (Here I also noticed about individual PE32/PE32+ tool at all, instead of IL Assembler, or something else. But it's hard for my time today, may be later...)

However, even this should not be a problem for most cases ...

Secondly, and most important :) you can simplify this chain via Conari if you need complex work with unmanaged libraries or even with data directly. +This also helps to prepare managed data for unmanaged environment, but if I understand correctly you need primary features of Coanri

See UnmanagedStructure and also native C/C++ structures without declaration here if you need.

c0nnex commented 7 years ago

Ok I will try to explain again ;) I will need the oposite of https://plus.google.com/101239554716569212042/posts/gR94gCu9k89

Works all fine if plugin.dll is c++. I now want to do plugin.dll in C#.

At the current point I am working on creating a c++-warpper dll which will export PANELS symbol, so FSX can set it, and my C#-dll exports some functions that will be called by the c++-dll to talk to each other. (maybe conari will help me there, i'll look into that)

3F commented 7 years ago

well, as I said above if 3rd party FSX can set this pointer only via variables, you should use another ways because ILAsm does not contain this logic today. Issue #24

The easy way, yes, to encapsulate this pointer for work through exported-functions as simple translator. Then you can call FLOAT64(FSAPI *get_named_variable_value) (ID id) as you need from C# etc.