flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Using an assembly DLL with C-Sharp. |
Author |
|
madmatt 13 Dec 2006, 22:59
I've just figured out how to use an assembly dll in C-Sharp, and example project is included below, along with the dll file that you can put either in your system32 folder, or in the Debug/Release folder along with the executable (Sorry for not releaseing the source, Later On I'll make a simple dll and use that in this example). I made this in Visual C-Sharp Express 2005 (the freebie from Microsoft). So you CAN use assembly in C-Sharp!!! I'm one very happy assembly programmer now , (I was before thanks to Tomaszs' FasmW, but now the glow is much brighter now! ).
|
|||||||||||
13 Dec 2006, 22:59 |
|
vid 13 Dec 2006, 23:19
i have read article from MS saying you can even mix C# procedures and asm procedures in single DLL
|
|||
13 Dec 2006, 23:19 |
|
madmatt 14 Dec 2006, 09:01
vid, kohlrak: You can use x86 assembly directly in your C++ code but NOT in C-Sharp code, you have to use a dll like my example above to use x86 assembly. x86 assembly was left out to make C-Sharp machine independent, but with apple moving to intel this is a moot point now. Almost all Desktop/Laptop OS's use intel/amd x86 processors now.
|
|||
14 Dec 2006, 09:01 |
|
vid 14 Dec 2006, 12:56
madmatt: i didn't say you can. what i was mentioning is called "mixed DLL" by MS. Search it on MSDN.
|
|||
14 Dec 2006, 12:56 |
|
madmatt 14 Dec 2006, 18:27
Here's pretty much the same example, but now shows how to import a windows api function and now uses the assembly dll found in the fasmw16x/examples/dll.
vid: Sorry, didn't mean to imply that you were wrong. But I read somewhere that you couldn't code x86 assembly directly into C-Sharp code, only in C++. How would you mix the two without creating A separate x86 assembly dll? Do you know of an example that demonstrates what you are talking about?
|
|||||||||||
14 Dec 2006, 18:27 |
|
vid 14 Dec 2006, 19:36
i just have read about that.
something is mentioned here: http://msdn2.microsoft.com/en-gb/library/aa290048(VS.71).aspx |
|||
14 Dec 2006, 19:36 |
|
RedGhost 14 Dec 2006, 23:34
All you have to do is use DllImport
[DllImport("dll", ... extra)] public static extern <type> <name> ( ... ); Sometimes you must flag your compiler to undecorate the exported stdcall functions. You can also define the type of string (unicode or ansi) and the convention, which defaults to stdcall. I use ufmod in my C# loaders this way. madmatt, C# also supports delegates (pointer to function), you can make a byte buffer of opcodes, append a retn and make a delegate to this and call it for "ghetto inline asm" in C#. Here is an example: http://www.atrevido.net/blog/PermaLink.aspx?guid=ac03f447-d487-45a6-8119-dc4fa1e932e1 _________________ redghost.ca |
|||
14 Dec 2006, 23:34 |
|
vid 14 Dec 2006, 23:59
it would be funny to have example of mixed dll
|
|||
14 Dec 2006, 23:59 |
|
madmatt 15 Dec 2006, 00:20
Redghost: The example you posted reminds me of using data statements on my old commodore 64 computer to "POKE" (store) an assembly program. (Damn! I hated typing in all that raw data ). You probably have no idea what a Commdore 64 was, so enough of that. While the example you posted will work, it will get complicated (and buggy) fast when you start using complex instructions, algorithms and gui functions. Because fasmw supports making compatible dll's, fasmw makes the whole process of using asm in managed code a LOT easier! (as my example shows).
vid: I think I see what you mean . I guess it is possible if you use Visual C++ .NET and the _asm keyword. I wonder if the _asm keyword works in C++ .NET . When I had Visual C++ installed, I never used C++ .NET, just standard C++. |
|||
15 Dec 2006, 00:20 |
|
vid 15 Dec 2006, 13:44
madmatt: i think such DLLs can be only created by linking "native" (x86) object with .net object. But that is just quessing
|
|||
15 Dec 2006, 13:44 |
|
Filter 03 Feb 2007, 16:34
vid wrote: madmatt: i think such DLLs can be only created by linking "native" (x86) object with .net object. But that is just quessing Actually (at least in .net 2.0) you can have hybrid native/managed dll. It doesn't matter if you have inline asm in the native parts of the dll. BTW: an example of a hybrid dll would be the SQLite ADO .NET 2.0 provider... http://sqlite.phxsoftware.com/ ... it doesn't contain assembler to my knowledge just native code. It can actually be used in place of the native code sqlite dll if necessary or just used as an ADO .NET 2.0 provider. |
|||
03 Feb 2007, 16:34 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.