Author Topic: C++ static library usage  (Read 10894 times)

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: C++ static library usage
« Reply #15 on: December 20, 2012, 11:05:51 AM »
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:
Code: [Select]
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

  • Member
  • *****
  • Posts: 9633
  • Assembler is fun ;-)
    • MasmBasic
Re: C++ static library usage
« Reply #16 on: December 20, 2012, 05:27:53 PM »
I 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


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

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: C++ static library usage
« Reply #17 on: December 20, 2012, 06:31:24 PM »
So 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

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: C++ static library usage
« Reply #18 on: December 20, 2012, 07:32:32 PM »
Works perfectly here (Win7,x64) - example attached.

EDIT: msvcrt.dll dependency removed.
« Last Edit: December 20, 2012, 09:32:53 PM by qWord »
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

  • Member
  • *****
  • Posts: 9633
  • Assembler is fun ;-)
    • MasmBasic
Re: C++ static library usage
« Reply #19 on: December 20, 2012, 08:26:30 PM »
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

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: C++ static library usage
« Reply #20 on: December 20, 2012, 09:21:10 PM »
So 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!

jj2007

  • Member
  • *****
  • Posts: 9633
  • Assembler is fun ;-)
    • MasmBasic
Re: C++ static library usage
« Reply #21 on: December 20, 2012, 09:37:46 PM »

hexbase

  • Guest
Re: C++ static library usage
« Reply #22 on: December 21, 2012, 04:34:19 AM »
Thanks guys for the help. It works perfectly now. I need to learn more about c++, my code is not good.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: C++ static library usage
« Reply #23 on: December 22, 2012, 09:38:14 PM »
Hi hexbase,

welcome to the forum.

Gunther
Get your facts first, and then you can distort them.