-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
How to properly use the "NativeStruct" from current Conari Version? #21
Comments
Sry, my bad, the code issue relied on smth else... forget this ticket! |
You're right, UnmanagedStructure is marked as obsolete and planned to be removed in future major releases. Please note, modern NativeStruct provides several ways https://github.com/3F/Conari/wiki/Quick-start#conari-types For example, you don't need a CLR types declarations at all if this is a fully automatic way, in your example, NativeStruct.Make.t<CharPtr, int>("a", "b").Struct; Also do not need a manual marshaling (Marshal.PtrToString...) everything is automated. This project unfortunately does not provide some good documentations today, but please first try my tests as an example:
Let me know if you still have some problems, I'll try to look into later. |
I see :) Just close it yourself if it's ok |
Thanks so far for that example! My only question now is: by using .NET 6, i am using "record struct" feature, to test this out, but since i have a feeling that it wont work like this, i created a struct-wrapper around that record-struct, like this: And would this code I have written to allocate unmanaged.memory for that wrapper be okay? have a look: Thanks in advanced! |
Why? Did you try it? ~
NativeStruct<SomeRecordStructDef> ns = new(instance); record struct (record ie. records) just tells the compiler to override some default operators and implements some extra logic in basic struct type for new features available in modern C# and so on. So I don't see the problem as long as it's marked as LayoutKind.Sequential. If you need some wrapping in any case, Well, you can implement some cloning of the available fields into some new type like SomeRecordStruct srs = ...
using NativeStruct<Wrapper> ns = new(srs.Clone()); Or note, NativeStruct also provides accessing to IntPtr if you want to wrap it inside somewhere somehow NativeStruct<Wrapper> ns = ...
IntPtr ptr = ns; etc. |
by the way, actually LayoutKind.Sequential limitation is not really ... FYI, https://twitter.com/github3F/status/1317526371921502210 |
@Shpendicus The "empty" export table does not related to NativeStruct use at all. This is not related even for .NET 6 limitation (I hope). As I said here 3F/DllExport#197 (comment)
Or, please open new issue on DllExport project as a bug since empty export directory. I'll investigate it later. Only please follow report steps and provide all minimal information about settings etc. Thanks. |
This is entire function to call the "public static int AllocRecord() {return 10 + 35};" function from .NET 6 and sadly, the equivalent call in Delphi, SEES my exported functions, i get a valid pointer from GetProcAdress(...) BUT when i call it, it shows;: "External Exception: 0434352" do you have maybe a clue how this possible? Again, both LoadLib and GetProcAdr do work! and return seeminlgy valid pointers, but then that exception raises for some reason. really strange. |
As I see, the "empty" problem is fixed now?
Depends on your configuration. Copy everything from DllExport's Data tab in GUI Did you try |
sry mate but how u mean "Copy everything from DllExport's Data tab in GUI" Did you try Use our IL Assembler + Rebase System Object ? |
About full sign, here 3F/coreclr#6
Too many features, dependencies, limitations, and a bit documentation. |
Mate, what im asking now may sound bit much, i admit, but still ; would you mind, adding me on Discord, and use "Share Screen" and watch me how I do the stuff, and then show me maybe, what i am doing wrong and correct me, (am using .net 6; VS 2022) i would pay u 3€+ per month :) so from 7 to 10€, if u only help me once with this, its so important for me, getting this done in time since i actually am writing for a company a software module, for my university-internship and i wanted to drastically get this work, managing writing code in new .NET 6 and call it from anywhere unmanaged, like Delphi/FPC/C++ etc.. |
@3F forget what i wrote (i will increase the payment to 10€ anyways, dw!) i made it work, bro :-D finally, i forgot to check in the Configurator in your image above, the option: "-nan(ind)" and then it worked fine :) The only thing now, i wonder: when i want to return string, or Datetime, as I can see for now, i get a valid pointer back from my function but when i cast my funcPtr to the proper and correct function definition: I wonder, why he cant execute that, Free pascal-Compiler executes with code "217", and aborts abruptly. What could cause this? |
:) I appreciate any support to me, however, something like this always reminds me of an attempt to buy me or my time in order to solve some tasks or even complete some work. But it costs a lot more.
I am glad to hear this!
For today's DllExport 1.7.4 the .NET 6 support is incomplete and more likely(*) will cause some related errors as it was mentioned earlier in DllExport repo. Try netstadard2.0, if it will work for the same code then this is it. If no, then something with marshaling that can be fixed in your code. |
Sry for that, that was the reason I regret formulating my sentence like this, I thought it actually more as a little motivation for a quick help ^^ (sry for that..) for the rest, well i think i will write the entire App for now in Delphi, its to complicated like this :D |
Why not temporarily decrease TFM to netstandard2.0 until fixes? or btw netfx-based such as net48 For better you can simply use conditional compilation. |
In your video: https://www.youtube.com/watch?v=QXMj9-8XJnY
you used the obsolete-way with UnmanagedStructure, now you suggest using the NativeStruct way, can u maybe give me a short example of how to make use of those properly, to be able to call it from C++/Delphi?
Because, when i compile the following code:
I get the error you can see in the "Error-dialogbox" below in the screenshot.
How to adapt to that new change you have done for Conari?
Much thanks!
The text was updated successfully, but these errors were encountered: