News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

C++ static library usage

Started by hexbase, December 20, 2012, 01:52:26 AM

Previous topic - Next topic

qWord

I've no clue why we need to use third party macros whereas MASM and VC supplies everything we need:
Just search in the Release folder for the import library re2.lib and copy this (and the DLL) to your project folder (MASM)
ASM:
includelib re2.lib
matchparcial proto STDCALL first:PVOID, second:PVOID
...
invoke matchparcial ,0,0

Also note that "string"-types are objects. You may change the paramters to char*.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: hexbase on December 20, 2012, 10:00:33 AMI put re2.dll in the masm32 folder and used: Dll "\masm32\re2.dll". When I run the program, it complains it cannot load the dll (loadlibrary). What im doing wrong?

No idea. Check the folder, or use this to test:
  Init
  Let esi="\RE2\re2.dll"
  .if !Exist(esi)
        MsgBox 0, esi, "Dll not found:", MB_OK
  .else
        Dll "\RE2\re2.dll"                        ; load the DLL
        Declare matchparcial, 2        ; matchparcial expects 2 pointers
        Inkey Str$("Result=%i", matchparcial("String1", "String2"))
  .endif
  Exit


Quote from: qWord on December 20, 2012, 11:05:51 AM
I've no clue why we need to use third party macros...

So did you get it running? No complaints about GetTickcount64? On a Win7-64 system I suppose?

qWord

Quote from: jj2007 on December 20, 2012, 05:27:53 PMSo did you get it running? No complaints about GetTickcount64? On a Win7-64 system I suppose?
No need to try it - he does not supplies a constructor for the class "string".
He should do all the OOP stuff in the DLL and use only none-object types for the function interface.
MREAL macros - when you need floating point arithmetic while assembling!

qWord

#18
Works perfectly here (Win7,x64) - example attached.

EDIT: msvcrt.dll dependency removed.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

The problem is somewhere in the original dll & lib. I got it "working", after obeying to messages requesting msvcp110.dll and msvcr110.dll, but then GetProcAddress did not find matchparcial in the dll. So I launched PeView, and matchparcial is clearly present as _matchparcial@8, it can be called with its ordinal value #1:

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Dll "\RE2\re2.dll"                        ; load the DLL
  Declare #1=matchparcial, 2        ; matchparcial expects 2 pointers
  Print Str$("Result=%i", matchparcial("String1", "String"))
  Exit
end start

... but the output is crappy:
re2\re2.cc:173: Error parsing 'String  Result=%i
ü@ Oü@ xü@ Öü@ ­©@ GetLastError...': invalid UTF-8
re2\re2.cc:768: Invalid RE2: invalid UTF-8
Result=0


In contrast, qWord's dll and lib work like a charm, both via the static lib and via the dll with ordinal #37:
Version 1, static only (but dll must be present!):
include \masm32\MasmBasic\MasmBasic.inc        ; download
includelib re2.lib
FullMatch PROTO :DWORD, :DWORD
  Init
  Print Str$("Result=%i", rv(FullMatch, "hello", "h.*o"))
  Exit
end start

Version 2, dynamically linked (but lib must be present!):
include \masm32\MasmBasic\MasmBasic.inc        ; download
includelib re2.lib
  Init
  Dll "re2.dll"                        ; load the DLL
  Declare #37=FullMatch, 2        ; ordinal works; matchparcial expects 2 pointers
  ; Declare FullMatch, 2          ; name not found in dll
  Print Str$("Result=%i", FullMatch("hello", "h.*o"))
  Exit
end start

Output for both:
Result=1


And both versions do not require the msvcp110.dll crap. So qWord, C++ jedi knight, how did you manage to reduce re2.lib from over 23MB to a mere 13,480 bytes?  :t

And why does GetProcAddress not find the FullMatch? Knowing that you don't trust "third party macros", here a plain Masm32 snippet:

include \masm32\include\masm32rt.inc
includelib re2.lib
.code
start:
   invoke LoadLibrary, chr$("re2.dll")
   .if eax
      xchg eax, ebx
      invoke GetProcAddress, ebx, chr$("FullMatch")
      MsgBox 0, str$(eax), "Hi", MB_OK
      invoke FreeLibrary, ebx
   .else
      MsgBox 0, "Could not load", "Hi", MB_OK
   .endif
   exit
end start


Edit: Mystery solved. It's Christmas time, so FullMatch needs the full decoration :badgrin:

  Declare _FullMatch@8, 2          ; that one works...
  Print Str$("Result=%i", _FullMatch@8("hello", "h.*o"))

qWord

Quote from: jj2007 on December 20, 2012, 08:26:30 PMSo qWord, C++ jedi knight, how did you manage to reduce re2.lib from over 23MB to a mere 13,480 bytes?
the compiler discarded everything that is not used by the function RE2::FullMatch.

BTW: the word Padawan may be more appropriate
MREAL macros - when you need floating point arithmetic while assembling!


hexbase

Thanks guys for the help. It works perfectly now. I need to learn more about c++, my code is not good.

Gunther

Hi hexbase,

welcome to the forum.

Gunther
You have to know the facts before you can distort them.