News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Masm32Ref

Started by mabdelouahab, January 14, 2016, 09:56:41 AM

Previous topic - Next topic

Zen

Hi, MABDELOUAHAB,
:bgrin: I think you just conquered the COM/NET Galaxy single-handedly. :bgrin:
:bgrin: MASM assembly language programming will never be the same. :bgrin:

mabdelouahab

Quote from: Zen on May 13, 2016, 06:59:49 AM
Hi, MABDELOUAHAB,
:bgrin: I think you just conquered the COM/NET Galaxy single-handedly. :bgrin:
:bgrin: MASM assembly language programming will never be the same. :bgrin:

Hi Zen,We are at your service.

Zen

#17
Hi, Again, MABDELOUAHAB,
Well, I've been making a preliminary scan of some of the Include files that you provided in your Sql Server & Masm32 example, (System.Data), and quickly reading through some of the source code that is downloadable from your SourceForge Masm32Ref site,...

DotNetHelper.INC, in particular, is immense,...:dazzled:,...I mean, mind-boggling immense,...and loaded with PROCS,... :dazzled:
:dazzled:...Which makes me wonder, how you conceived of everything that goes into the process of creating Masm32Ref,...:dazzled:

I don't want you to give away all your secrets,...but, I've got a million questions,...:icon_eek:

...Anyway, I tried using the Masm32 Ref utility on something I thought  I knew something about,...the .NET Framework assembly, System.Xml Version 4.0.0.0. Well, I'm happy to report that in addition to the System.Xml.INC file (18 Kb), that lists all the other include files in the package, MASM32Ref produced 266 files, comprising 2.33 MB (size on disk). Again,...immensely mind-boggling,...:dazzled:   And, it appears, just on the initial inspection, that these include files and their type definitions would work perfectly with MASM32,...:dazzled:

The MSDN .NET Framework Version 4.5, Class Library, System.Xml Namespace documentation is here: System.Xml Namespace

...So, I'm wondering,...let's say, for example, I wanted to create a MASM32 application that uses the System.Xml classes, interfaces, and methods,...
I would include the appropriate Xml include files (created by Masm32Ref) at the beginning of my main assembly file,...and,...:dazzled:
How do I link my program's assembly language files to a .NET Framework assembly ??? I'm guessing that the MASM compiler (ml.exe) cannot read .NET Framework assemblies, even though they are in essence, normal DLLs with an extra section that describes the .NET metadata.

Is it necessary to compile this MASM32 project with Visual Studio ???
What about the possibility of using the .NET Framework Tool, Tlbexp.exe (Type Library Exporter) to generate a Type Library ???

...I had to go back and re-read: Really Bizarre Question, July 2013 , because I'd forgotten all that stuff. The article: Injecting .Net Assemblies Into Unmanaged Processes, CodeProject was useful.

MSDN documentation: Hosting the Common Language Runtime

...You know,...I've completely forgotten all the .NET/COM interop techniques that I learned from: ".NET and COM: The Complete Interoperability Guide", by Adam Nathan.

mabdelouahab

Hi Zen
First I'm sorry I no better English, I just use the translator
Quote from: Zen on May 14, 2016, 05:26:18 AM
I don't want you to give away all your secrets,...but, I've got a million questions,...:icon_eek:
I don't have secrets, "It's science", and I'll answer to 2 million question

MASM32Ref  is not magic, Is just a translation of what exists in "Hosting the Common Language Runtime" to Assembly language, it cost me two years,and it is not necessary to compile your project with Visual Studio, I personally use the RadAsm IDE.

MASM32Ref make for you a MACROs ready for direct use, and it initialise the last CLR automatically for you if you have not done so
You can use the full namespace include file , also you can use one type include file
I will give you the simplest example "Hello world"
Quoteinclude System.Windows.Forms.MessageBox.inc
include masm32rt.inc
.data
   msg__   = BSTR$("Hello World")
   
    vString   dw VT_BSTR,0,0,0
                    dd msg__,0
.code
Start:
   System_Windows_Forms_MessageBox_Show_14 addr vString,0
   inkey
   exit
end Star
t

You may notice that I used a single include file of the class: System.Windows.Forms.MessageBox

You may notice that I used System_Windows_Forms_MessageBox_Show_14 method, Why 14, because there are 21 method Show, and when you return to the include file "System.Windows.Forms.MessageBox.inc" you will find that before each macro find a comment to the method  to be used
Quote
   
...
   ;[Static];System.Windows.Forms.DialogResult Show(System.String, System.String)
      System_Windows_Forms_MessageBox_Show_13 MACRO  _text ,_caption ,lpvtRetValue
         ??DEF_System_Windows_Forms_MessageBox
         invoke __NetFWHelper_Method,addr __Type_System_Windows_Forms_MessageBox,13,0,lpvtRetValue,2, _text ,_caption
      ENDM
      ;[Static];System.Windows.Forms.DialogResult Show(System.String)
      System_Windows_Forms_MessageBox_Show_14 MACRO  _text ,lpvtRetValue
         ??DEF_System_Windows_Forms_MessageBox
         invoke __NetFWHelper_Method,addr __Type_System_Windows_Forms_MessageBox,14,0,lpvtRetValue,1, _text
      ENDM
...

You may notice that I used vString as VARIANT, because any argument passed  (or return) must be in the form of VARIANT, and 0 means null variant

Zen if you wanted to create a MASM32 application that uses the System.Xml namespace, just include "System.Xml.INC" before any other inc file then use what you want from him, 

I think it is better to define me in .net example to show you how you can turn it into an example of masm32

Zen

#19
Thanks, MABDELOUAHAB,
The explanation is clear and simple,...thank you. I'll try it,...and then, I'll post some code. :bgrin:
I know I'm repeating myself,...but, Masm32Ref is a great tool. :bgrin:
I've read a number of the include files created by Masm32Ref,...and, at first, the macros confused me (just because I don't really understand how macros work). But, after, studying them for awhile, they seem clear and actually easy to understand. I think that you probably used the simplest and most reliable method to design the .NET to MASM object conversion macro. Again, an incredibly useful utility. :bgrin:

mabdelouahab

Thanks Zen, Again, We are at your service. :biggrin:

habran

Good job mabdelouahab :t
What about MASM64Ref or even better: HJWASM64Ref ;)
Cod-Father

mabdelouahab

Hello habran
Quote from: habran on May 15, 2016, 08:09:02 AM
What about MASM64Ref or even better: HJWASM64Ref ;)
It's summer project  :lol:

habran

When is a summer in your country ;)
Cod-Father

Zen

#24
:bgrin: MABDELOUAHAB !!! :bgrin:
Hi. I've been working on a MASM project to write an XML file (using the .NET Framework, System.Xml assembly), like I mentioned above.
At this point, I've become semi-crazy (well,...probably, seriously demented),...it's not difficult, but, it's tedious coding. Anyway, I've read an enormous amount of MSDN .NET Framework documentation, and, I've written routines to enumerate installed CLRs and then to load a version of the CLR (version 4). And,...I thought I was doing OK,...everything was working just fine,...:bgrin:

Then, I got to the part where I would be creating an actual XmlWriter (to create an XML Document),...and, I started seriously reading a number of those System.Xml include files that were created by MASMRef,...and, naturally,...I started reading DotNetHelper.inc in depth,...and, I realized, to my horror,...that you have already done all the COM interface instantiation, CLR enumerating, loading and initializing that I've spent several weeks doing on my own.
In fact, DotNetHelper.inc is the key to the entire .NET Framework CLR hosting process. If you are going to write an unmanaged MASM process to host the .NET Framework Common Language Runtime, it's the first file you should read.
And, you did it so well !!! I'm REALLY impressed. I'm learning alot of cool assembly programming techniques just from reading that file.

...I wondered what you meant when you said,
Quote from: MABDELOUAHABMASM32Ref make for you a MACROs ready for direct use, and it initialise the last CLR automatically for you if you have not done so.

:bgrin:...It's just WAY TOO EASY,...almost FUN,...:bgrin:  It's quite possible that you've thought of everything,...:bgrin:

Zen

Well, OK,...I have run into a problem. There is a MACRO defined in ComHelper.inc, (BSTR$) the code is like this:   

   BSTR$   MACRO   qstr:vararg
      LOCAL arg,qot,q,bstrLbl,bstr_Seg,FrstL,tmpLen,cur_Pos,tmpStr,cur_tPos
      cs_Seg catstr @CurSeg
       ifidn cs_Seg, <CONST>
          bstr_Seg    TEXTEQU   <.const>              
       elseifidn cs_Seg, <_BSS>
          bstr_Seg    TEXTEQU   <.data?>
       elseifidn cs_Seg, <_DATA>
          bstr_Seg    TEXTEQU   <.data> 
       elseifidn cs_Seg, <_TEXT>
          bstr_Seg    TEXTEQU   <.code>         
       endif
         .data
            dd   _LenBSTR(qstr)
      FrstL   =   0
      FOR arg,<qstr>
         tmpStr equ <>
         qot SubStr <arg>,1,1
         IFIDNI qot,<!'> 
            tmpLen   =   @SizeStr(<arg>)
            tmpLen   =   tmpLen - 2
            cur_Pos    =   1
            cur_tPos   =   0
            repeat tmpLen
               cur_Pos=cur_Pos+1
               cur_tPos=cur_tPos+1
               ch_unq SubStr <arg>,cur_Pos,1
               IF   cur_Pos eq 2
                  tmpStr CATSTR tmpStr,<!">,ch_unq,<!">
               ELSE
                  IF   cur_tPos eq 1
                     tmpStr CATSTR tmpStr,<!">,ch_unq,<!">
                  ELSE
                     tmpStr CATSTR tmpStr,<!,">,ch_unq,<!">
                  ENDIF
               ENDIF
               IF   cur_tPos eq 15
                  IF FrstL   eq 0
                     bstrLbl   dw   tmpStr
                     FrstL   =   1
                  ELSE
                           dw   tmpStr
                  ENDIF
                  cur_tPos   =   0
                  tmpStr CATSTR <>
               ENDIF
            endm
            IF tmpLen ne 0
               IF cur_tPos ne 0
                  IF FrstL   eq 0
                     bstrLbl   dw   tmpStr
                     FrstL   =   1
                  ELSE
                           dw   tmpStr
                  ENDIF
               ENDIF
            ENDIF
         ELSEIFIDNI qot,<!">
            tmpLen   =   @SizeStr(<arg>)
            tmpLen   =   tmpLen - 2
            cur_Pos    =   1
            cur_tPos   =   0
            repeat tmpLen
               cur_Pos=cur_Pos+1
               cur_tPos=cur_tPos+1
               ch_unq SubStr <arg>,cur_Pos,1
               IF   (cur_Pos eq 2)
                  tmpStr CATSTR tmpStr,<!">,ch_unq,<!">
               ELSE
                  IF   (cur_tPos eq 1)
                     tmpStr CATSTR tmpStr,<!">,ch_unq,<!">
                  ELSE
                     tmpStr CATSTR tmpStr,<!,">,ch_unq,<!">
                  ENDIF
               ENDIF
               IF   cur_tPos eq 15
                  IF FrstL   eq 0
                     bstrLbl   dw   tmpStr
                     FrstL   =   1
                  ELSE
                           dw   tmpStr
                  ENDIF
                  cur_tPos   =   0
                  tmpStr CATSTR <>
               ENDIF
            endm
            IF tmpLen ne 0
               IF cur_tPos ne 0
                  IF FrstL   eq 0
                     bstrLbl   dw   tmpStr
                     FrstL   =   1
                  ELSE
                           dw   tmpStr
                  ENDIF
               ENDIF
            ENDIF
         ELSE
            IF FrstL   eq 0
               bstrLbl   dw   arg
               FrstL   =   1
            ELSE
                     dw   arg
            ENDIF
         ENDIF
      ENDM
      IF FrstL   eq 0
         bstrLbl   dw   0
      ELSE
               dw   0
      ENDIF
      bstr_Seg
      EXITM <OFFSET bstrLbl>       
   ENDM


To be perfectly honest, I don't understand what it does, except that I'm guessing that it creates a BSTR. It's called numerous times in DotNetHelper.inc, with syntax like this:
invoke CompareString, LOCALE_USER_DEFAULT, NORM_IGNORECASE, __lpstrname,9,BSTR$("mscorlib,"),9

And, everywhere this macro is called, I'm getting the following error when compiling:
error A2085: instruction or register not accepted in current CPU mode. No clue as to why,...:icon_eek:

What I really don't understand is: when I was including the ComHelper.inc and DotNetHelper.inc into my project, I knew I was going to get compiler errors, so I included the ComHelper.inc file first, but, NOT, the DotNetHelper.inc file, just to see what kind of errors I was going to get,...and the project compiled without any errors at all. Apparently, the MACRO syntax will compile, but, is not expanded until it is actually invoked in the source, is this correct ?

...And, by the way,...what does ELSEIFIDN mean ??? I've looked everywhere, and could not find a definition for it,...

hutch--

Zen,

What processor model are you using ?

Quote
And, everywhere this macro is called, I'm getting the following error when compiling:
error A2085: instruction or register not accepted in current CPU mode. No clue as to why

Try 686p, MMX, XMM

From masm32.chm

[ELSE]IFDIF


Syntax: [ELSE]IFDIF textitem1, textitem2

[ELSE]IFIDN textitem1, textitem2


Description

Causes assembly of a block of statements depending on whether two textitems are different or identical. IFDIF assembles the block if <textitem1> and <textitem2> are different. IFIDN assembles the block if they are the same. IFDIFI and IFIDNI do the same actions but are not case sensitive.

The <textitem1> and <textitem2> parameters are text items.


NOTE: The MASM macro notation messes up the formatting of the BBC tags.

mabdelouahab

ZEN
I did not update "ComHelper.inc", but there is a new update for file "Masm32Ref.Inc", it contains BSTR$  macro differs from existing in the first file

mabdelouahab

Last update:

1. BSTR$ Macro: Corrected in the correct size while you insert 2 Quot ; ex:BSTR$("my name is ""MA"".")

2. __ForEach Macro: To get a loop for each value in a array
Syntax:
Quote__ForEach MyVariable in MyArray
            ; ....
            __ExitFor  ; exit __ForEach
            ; ....
            RET        ; go to the next
            ; ....
         __Next

MyVariable : pointer to Variant

3. During the generation of macro properties, add a number to the properties of the same name within the same object.

4. the Injector: Solve the problem of lack success running on different OS




Zen

#29
MABDELOUAHAB,
Hi, again. Yeah, after I posted yesterday about the BSTR$ Macro, I read the Masm32Ref.Inc file (listed at SourceForge), and noticed the different version of the BSTR$ Macro,...and, I wondered why there would be two versions. Anyway, I read the original BSTR$ Macro, and, I didn't even find any instructions,...much less an instruction or register that could be considered "Not accepted in the current CPU mode". I still HAVE NO IDEA why I'm getting these same errors when compiling,... :icon_eek: Maybe, this BSTR$ Macro should be a routine (or group of routines) instead of a Macro,...I'll try that,...just to see if I can actually locate the cause of the error,...

HUTCH,
Quote from: HUTCHWhat processor model are you using ?
Yeah, first thing I thought of. I'm using the .486 model directive (the same as MABDELOUAHAB is using in his include files). But, I did change it, and then tried to compile,...and got the same error. I'll have to play around with that macro some and see what happens,...
Thanks for the info on the IF/ELSE variants, (and, where to find the information),...

UPDATE: Ok, I downloaded the new Masm32Ref.Inc file from the MASMRef SourceForge site, substituted the "new, updated"  BSTR$ Macro into ComHelper.inc in my MASM project, and tried to re-compile. I got the same errors. Sorry,...
The only way I can get the MASM project to compile, is to comment out all the instances in the code of DotNetHelper.inc that have the  BSTR$ Macro in them (there are over 130 BSTR$ Macro invokes). Of course, I can't actually CALL any of those routines,...