Skip to content
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

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

Open
c0nnex opened this issue Feb 15, 2017 · 3 comments
Open

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

c0nnex opened this issue Feb 15, 2017 · 3 comments

Comments

@c0nnex
Copy link

c0nnex commented Feb 15, 2017

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
Copy link
Owner

3F commented Feb 16, 2017

` >_< 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
Copy link
Author

c0nnex commented Feb 16, 2017

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

  • Software (MS FSX , pure c/c++) defines a struct (PANELS) (http://www.prepar3d.com/SDKv2/LearningCenter/simobjects/sample_code/gauges.html) that contains function pointers.
  • I can plugin a c++-dll into FSX.
  • if plugin.dll exports a symbol called "PANELS" , this symbol will be set by FSX to the structure offset when plugin is loaded.
  • I want to call one of the functions in that struct e.g. "FLOAT64(FSAPI *get_named_variable_value) (ID id)" (which is "double (__stdcall get_named_variable_value) (int id)" when resolving the Macros)

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
Copy link
Owner

3F commented Feb 16, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants