flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Correctly calling dll proc from c#, return value issues |
Author |
|
typedef 02 Oct 2019, 22:44
You have to allocate that array somewhere. Either pass an Int32 array/structure to the function or have the function allocate the memory for you, which means you'll also have to have the DLL free the memory.
If you are feeling adventurous you can even go to the extreme and use shared memory, PIPES, and even sockets. |
|||
02 Oct 2019, 22:44 |
|
juergenkulow 05 Oct 2019, 13:27
Hello jmurray,
Code: using System; using System.Runtime.InteropServices; namespace TestDLL{ class Program { [DllImport("D:\\Test-DLL.dll" , EntryPoint= "MethodOneID")] public static extern int MethodOneID([In,Out] long [] regcx); private static long[] buffer = new long[] { 1, 2, 3 }; static void Main(string[] args) { MethodOneID( buffer); Console.WriteLine(buffer[0]); Console.WriteLine(buffer[1]); Console.WriteLine(buffer[2]); Console.ReadLine(); } } } Code: format PE64 console DLL entry DllEntryPoint include 'win64a.inc' section '.text' code readable executable proc DllEntryPoint hinstDLL,fdwReason,lpvReserved mov eax,TRUE ret endp proc MethodOne uses rcx rdtsc mov [rcx],eax add rcx,4 mov [rcx],edx add rcx,4 MFENCE ;measure timestamp rdtsc mov [rcx],eax add rcx,4 mov [rcx],edx add rcx,4 push rcx ; CPUID delete rcx MFENCE ;Code to measure CPUID ;measure timestamp rdtsc pop rcx mov [rcx],eax add rcx,4 mov [rcx],edx add rcx,4 MFENCE Mov rax,rcx ret endp section '.bss' data readable writeable bytes_count dd ? section '.edata' export data readable export 'Test-DLL.DLL',\ MethodOne,'MethodOneID' section '.reloc' fixups data readable discardable if $=$$ dd 0,8 ; if there are no fixups, generate dummy entry end if |
|||
05 Oct 2019, 13:27 |
|
jmurray 05 Oct 2019, 19:14
Fantastic. Thanks juergenkulow. That works and clears up a lot if my misconceptions. I should be alright from here on out.
|
|||
05 Oct 2019, 19:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.