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

mabdelouahab

Masm32Ref idea adapted from advanced programming languages, you can add a reference to your project and use it directly, such as Visual Studio, on the Project menu choose Add reference, I wanted to make the same thing for Assembly programmers

Masm32Ref is a free Software, is intended for Assembly programmers, to extract the .INC file to direct access to COM objects and .net object, contains everything a programmer, for use directly without adding or modifying,
This work is primary, improvement, development and auditing, but this depends on the participation of everyone, because it's free and for everyone

Masm32Ref contains open source helper files plus tools to extract reference files; it also contains a utility to inject .net code within your program
The tool contains three axes:
   •   Extract COM object
   •   Extract dot net object
   •   Injector


Extract COM object
I will explain how to use by examples, and I propose to this example, https://msdn.microsoft.com/en-us/library/office/ff838565.aspx
If the object name is "Word.Application", we will replace the point "." by "_" will become the name of the object '' Word_Application"
To get an new instance add "New_" to the name of the object with the addition of a variable either defined or not defined
   New_Word_Application   _WordApplication

Then you can call any Method or Property by adding the name of the function to the name of the object
For example:
Method "Open": Word_Documents_Open
Property " Visible " : Word_Application_Visible_Set
to set up an event proc receiver add "_On_" after the name of the object and add Event name
Event "Quit"    : Word_Application_On_Quit
Application:
First, download the tool,and the helper (copy COMHelper.inc to \Masm32\Include)
Second, after execution Choose List Registred COM TypeLibrary

Go to : Microsoft Word ?? Object Library , I have Microsoft Word 15.0 Object Library
Double Click then Choose OutPut Folder, You will get a file Word.INC
Open a new empty project , and write the following code
Quoteinclude word.inc
.data
   _WordDocuments   dd   0
   _WordDocument   dd   0
.code
   ON_Application_Quit    PROC __Inst_Obj:DWORD
      invoke MessageBox,0, chr$("ON_Application_Quit"),0,0
       RET   
   ON_Application_Quit    ENDP
Start:
   New_Word_Application         _WordApplication
   Word_Application_Visible_Set   _WordApplication,TRUE
   ;Event   :   Quit
   Word_Application_On_Quit      _WordApplication,offset ON_Application_Quit
   
   Word_Application_Documents_Get    _WordApplication,addr _WordDocuments
   Word_Documents_Open         _WordDocuments,__String("d:\01.doc"),,,,,,,,,,,,,,,,addr _WordDocument
   inkey
   __Release _WordApplication
   exit
end Start

Try it

Second example:   https://msdn.microsoft.com/en-us/library/windows/desktop/aa393960%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
Microsoft WMI Scripting V1.2 Library (WbemScripting.SWbemLocator)
Quote
include WbemScripting.INC
   .data
      _ISWbemServices      dd   0
      _SWbemObjectSet      dd   0
      _ISWbemObject      dd   0
      _ISWbemPropertySet   dd   0
      _ISWbemProperty      dd   0
      _varValue            VARIANT   <>
   .code
Start:

   New_WbemScripting_SWbemLocator _SWbemLocator
   WbemScripting_SWbemLocator_ConnectServer    _SWbemLocator,BSTR$("."),BSTR$("root\cimv2"),0,0,0,0,0,0,addr _ISWbemServices
   WbemScripting_SWbemServices_ExecQuery      _ISWbemServices,BSTR$("Select * From Win32_ComputerSystem"),BSTR$("WQL"),0,0,   addr _SWbemObjectSet
   WbemScripting_SWbemObjectSet_ItemIndex       _SWbemObjectSet,0,addr _ISWbemObject
   WbemScripting_SWbemObject_Properties__Get    _ISWbemObject,addr _ISWbemPropertySet

      ;===========================================   Name
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("Name"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n Computer name   :%s"),_varValue.bstrVal
      ;===========================================   NumberOfProcessors
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("NumberOfProcessors"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n Nb Processors   :%d    "),_varValue.lVal
      ;===========================================   Workgroup
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("Workgroup"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n Workgroup   :%s   "),_varValue.bstrVal
      ;===========================================   BootupState
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("BootupState"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n BootupState   :%s   "),_varValue.bstrVal
      ;===========================================   DNSHostName
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("DNSHostName"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n DNSHostName   :%s    "),_varValue.bstrVal
   
      invoke crt_wprintf,cfm$("\n \n ")
   inkey
   exit
end Start

I am looking for everyone's participation to improve the tool
I will complete with .net later

To get the latest update Visit https://sourceforge.net/projects/masm32ref/files/

qWord

The Word-example directly worked  :t

The file COMHelper.inc does include code/data and also references masm32rt.inc.
I would at least move the code and data into separate asm files, or better supply them via a static library.  The reference to masm32rt.inc should be completely removed IMO.
There is some redundant macro code (__New_float/double/short,....) that could be removed by using macros that define other macros (afaics).

regards
MREAL macros - when you need floating point arithmetic while assembling!

guga

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Works great on Win7-64 :t

Here is my version :P

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  SendWordCommands      ; prepare a DDE session; Word must be running
  .if eax
      void FileRead$("http://masm32.com/board/index.php?topic=5028.0")
      Let esi=CurDir$()+"Masm32Ref.htm"
      Rename "~FrLocal.tmp", esi
      SendWordCommands Cat$('[FileOpen "'+esi+'"]')
      SendWordCommands '[MsgBox "Cute"]'
  .else
      MsgBox 0, "MS Word doesn't answer", "Sorry", MB_OK
  .endif
  SendWordCommands exit      ; finish DDE session
EndOfCode

guga

I managed to make it work after manual patching the file. The PE Section IMAGE_OPTIONAL_HEADER on the members MajorOperatingSystemVersion and MajorSubsystemVersion are marked as 6 that does not work on earlier versions of windows :(

After changing them to 4, the app runned. Btw,...i liked it a lot ! I wonder if you could make it also export RosAsm version of this macros too ;)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

mabdelouahab

#5
Hello qWord,guga,jj2007
We will discuss a lot
But let me complete the examples and then I will come back
Extract dot net object
after execution Choose List Registred .net Assembly
for example just, select System.Windows.Forms
Double Click then Choose OutPut Folder, You will get a file "System.Windows.Forms.INC"
Open a new empty project , and write the following code
Quote
include System.Windows.Forms.inc
.code
   On_Click   PROC _sender:VARIANT, _e:DWORD
      LOCAL vt_e:VARIANT
      mov vt_e.vt,VT_DISPATCH;  VT_UNKNOWN
      m2m vt_e.punkVal,_e
         invoke MessageBox,0,BSTR$("On_Click"),0,0
      RET
   On_Click   ENDP

start:

   invoke __InitCLR
   .if eax
      New_System_Windows_Forms_Form             Form1
         System_Windows_Forms_Form_Text_Set      Form1,__String("My First Form")
         System_Windows_Forms_Button_SetBounds    Form1,__Integer(640),__Integer(480),__Integer(640),__Integer(480)
      
      New_System_Windows_Forms_Button            Button1
         System_Windows_Forms_Button_Text_Set    Button1,__String("My First Button")
         System_Windows_Forms_Button_SetBounds    Button1,__Integer(100),__Integer(100),__Integer(160),__Integer(60)

         System_Windows_Forms_Button_On_Click       Button1,offset On_Click
   
      __New_Null Controls
      System_Windows_Forms_Control_Controls_Get   Form1,Controls
      System_Windows_Forms_Control_ControlCollection_Add Controls, Button1
   
      System_Windows_Forms_Form_ShowDialog       Form1,0
      invoke __ReleaseClr
   .endif
   exit
end start

mabdelouahab

#6
Copy DotNetHelper.inc to \Masm32\include

TouEnMasm


Help possible with the source code of Masm32Ref.exe
Fa is a musical note to play with CL

mabdelouahab

Injector
Injector is a tool to help you insert the .net code within your program directly
after execut masm32Ref Choose Injector
Copy this Code example:
Public Class MyClass1
    Public Function MyFirstFunc(s As String) As System.Windows.Forms.DialogResult
        Return System.Windows.Forms.MessageBox.Show("Masm32 Injector:"+s, "Masm32Ref")
    End Function
    Public Shared Function MySecFunc(s As String) As System.Windows.Forms.DialogResult
        Return System.Windows.Forms.MessageBox.Show("Masm32 Injector:"+s, "Masm32Ref")
    End Function
End Class

click "Add Ref" and select System.Windows.Forms.dll
click "Generat Inc File" ,type the assembly name "MyAssembly",Choose OutPut Folder, You will get a file "MyAssembly.INC"
Open a new empty project , and write the following code
Quote
include MyAssembly.inc

start:

   invoke __InitCLR
   .if eax
      __New_Empty   _msgRet
      ;Static function
      MyClass1_MySecFunc __String("Hello"),_msgRet

      New_MyClass1    _cls1
      MyClass1_MyFirstFunc _cls1,__String("Hello"),_msgRet
      invoke __ReleaseClr
   .endif

   inkey
   exit
end start

TWell

Statusline is too narrow in Windows 10

mabdelouahab

Quote from: qWord on January 14, 2016, 11:49:49 AM
The Word-example directly worked  :t

The file COMHelper.inc does include code/data and also references masm32rt.inc.
I would at least move the code and data into separate asm files, or better supply them via a static library.  The reference to masm32rt.inc should be completely removed IMO.
There is some redundant macro code (__New_float/double/short,....) that could be removed by using macros that define other macros (afaics).

regards

Thank you qWord Good observation, I've removed  masm32rt.inc. I've added what I need only

mabdelouahab

Quote from: TWell on January 14, 2016, 07:38:13 PM
Statusline is too narrow in Windows 10

Thank you TWell   I reset to default font, If you have experience in colors and fonts please suggest us



HSE

Apparently it's posible download only one com object by session, second time nothing happen.
Equations in Assembly: SmplMath

mabdelouahab

Thank you HSE  :t, You can download the latest update,You must download the files: Masm32Ref.lib and Masm32Ref.inc, Also you can download Masm32RefMacro.INC, I took the tip of qWord to make the tool work well with Masm ,jwasm,hjwasm,and rosasm, I've put COMHelper.INC and DotNetHelper.INC inside static lib and dynamic link lib

All that is >>> here <<<

You can enjoy with .net object and COM object

HSE

Equations in Assembly: SmplMath