Author Topic: Visual Basic 2010/2013 and MASM  (Read 7411 times)

David BS

  • Regular Member
  • *
  • Posts: 30
Visual Basic 2010/2013 and MASM
« on: July 09, 2014, 03:27:19 PM »
Hi All!

I have some doubts about integrate pure ASM code into my Visual Studio applications. Could someone help me please?

1- I had developed a C++ application to call an ASM function (CPUID) using NASM/YASM, passing pointers of a string in C++ to the ASM file. In debug mode I can see the pointers are well received by ASM and the bytes change as expected. But when the ASM code ends and return to C++ the memory data is UNCHANGED! It seems the ASM code didn't change nothing. I checked the pointers addresses and I'm sure it's 100% right (I had tested changing the source bytes there and checking in ASM code if I was seeing the same bytes).

2- Is there any way to utilize ASM LIB files from my Visual Basic sources (as a DECLARE or something like that)?

3- Is there any way to compile MASM64 code to .OBJ or .DLL and utilize it from my Visual Basic 2010/2013?

I would appreciate ANY help about these doubts.
Thanks a lot.

jj2007

  • Member
  • *****
  • Posts: 9385
  • Assembler is fun ;-)
    • MasmBasic
Re: Visual Basic 2010/2013 and MASM
« Reply #1 on: July 09, 2014, 04:46:59 PM »
All of that is possible (we discussed that), but without seeing any code, it's difficult to see where the problem is. You have a standalone VB app, or is it VB for apps? What can you zip & post here?

Re 1., have you checked if VB passes a copy of the original memory?

Using a 32-bit dll or lib with 64-bit code is NOT possible, of course.

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Visual Basic 2010/2013 and MASM
« Reply #2 on: July 09, 2014, 11:16:37 PM »
it might be easier to write a PROC in asm, assemble to an OBJ or LIB, then link it
but, i am sure there's a way to inline it, as well

David BS

  • Regular Member
  • *
  • Posts: 30
Re: Visual Basic 2010/2013 and MASM
« Reply #3 on: July 09, 2014, 11:46:58 PM »
Thank you very much to you both.

Yes, I'll provide the code to you, but I need some days since during the work days it's really impossible to me since I have two jobs in different companies and I travel almost every day.  But I promise that until the next weekend I'll upload it here.

My main goal is not just CPUID check, but:

1- check if CPU supports AVX os SSE 4.x instructions;
2- to call INTEL NASM code for SHA512 and perhaps AES-IN encryption.

I wonder that the *BEST* way is to make a C++ DLL to call ASM code (there is YASM/NASM not MASM one since they're INTEL resources), but I **REALLY** would like to make it only with Visual Basic + ASM CODE.

I'm very used to MASM32 since DOS time and I made some code to interface with VB6 some years ago. But I believe that now, with .NET Visual Basic, it is not possible to exchange data between VB and ASM...    :(

I'll send the code as soon as possible!  Thanks again for the support guys.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6262
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Visual Basic 2010/2013 and MASM
« Reply #4 on: July 09, 2014, 11:48:00 PM »
If I remember correctly 64 bit CL.EXE does not allow inline assembler so you are stuck with writing a module in MASM64 and linking it into the C/C++ code. If you have a way to interface C/C++ with VB then you have a technique to run assembler code from VB. You will need to get things like calling conventions right and 64 bit Windows is a lot more complicated than 32 bit in this area. From the very little I have seen of later VB.NET, its a really different animal to the older VB6 era and I personally don't know what its capacity is but if you can call C/C++ code you have a path to do what you need.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Visual Basic 2010/2013 and MASM
« Reply #5 on: July 10, 2014, 12:17:38 AM »
it doesn't need to be in a DLL
it can be in a static library

and - to exchange data, pass a pointer to a structure
let the asm module fill in the structure

as for CPUID and AVX....
as it happens, Gunther and I have both made some recent posts regarding these issues
the forum search tool might provide some help   :t

David BS

  • Regular Member
  • *
  • Posts: 30
Re: Visual Basic 2010/2013 and MASM
« Reply #6 on: July 10, 2014, 12:34:08 AM »
Thank you Hutch, Dedndave!
I'll see what you advise to me, for sure.
See you as soon as possible.

And thank all of you for help and support. You're bad!

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: Visual Basic 2010/2013 and MASM
« Reply #7 on: July 10, 2014, 02:17:53 AM »
And thank all of you for help and support. You're bad!

What's that?  :( Could you explain it?

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

jj2007

  • Member
  • *****
  • Posts: 9385
  • Assembler is fun ;-)
    • MasmBasic
Re: Visual Basic 2010/2013 and MASM
« Reply #8 on: July 10, 2014, 03:41:17 AM »
I believe that now, with .NET Visual Basic, it is not possible to exchange data between VB and ASM...

If you can use the Windows API, e.g. Private Declare Function CreateWindowEx(...), then you can also use your own functions and procedures. I can't help you with 64-bit code, though, but some members here have quite a lot of experience - wait and see ;-)

David BS

  • Regular Member
  • *
  • Posts: 30
Re: Visual Basic 2010/2013 and MASM
« Reply #9 on: July 10, 2014, 04:29:04 PM »
For some people like me, a single letter is enough to understand the entire sentence... 
I got success picking pieces of information of all of you.  :greenclp:

Yes, jj2007, I was not supposing to mix x86/x64 codes. My problem was focused in blend Visual Studio Basic 2010/2013 with pure ASM code (via DLL). Some x86 DLL files weren't being correctly loaded from VB and I hadn't realized why.

Dedndave told me to work with structures instead pointers and it was crucial to solve my problem. I can now call the CPUID in ASM from within VB 2010/2013 and get the results to check if the computer is able to process INTEL AES-NI and SHA512 codes. My target is get more performance than .NET can provide.

Because of these few words from these guys (and a lot of patience and willingness to help me) I told them, Gunther, they're really bad (in other words, they ARE the guys!). They helped me quickly and in an effective way. One more time I thank you all.  :t :t

Just seizing the opportunity: can EasyCode work with YASM? I had success making MASM syntax in it but the codes I'm looking for are made all in YASM syntax (via INTEL). EasyCode really makes easy to program in ASM since it has some macros and templates to help us. Do you know some equivalent tool for YASM?

Kindest regards to all of you.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6262
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Visual Basic 2010/2013 and MASM
« Reply #10 on: July 10, 2014, 04:42:01 PM »
Some of these poor old fellas failed to get it where I got it the first time, it works the same way as "A good woman is hard to find and a BAD one is nearly impossible to find".  :biggrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: Visual Basic 2010/2013 and MASM
« Reply #11 on: July 10, 2014, 07:25:28 PM »
Just seizing the opportunity: can EasyCode work with YASM?

You should ask that question here.

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

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Visual Basic 2010/2013 and MASM
« Reply #12 on: July 10, 2014, 09:37:41 PM »
Gunther, if you want to understand "bad = good". i suggest these 2 movies...
The Whole Nine Yards, The Whole Ten Yards
in the second movie, you will get the picture, but the first movie is a must-see   :P

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: Visual Basic 2010/2013 and MASM
« Reply #13 on: July 11, 2014, 12:02:15 AM »
Hi Dave,

Gunther, if you want to understand "bad = good". i suggest these 2 movies...
The Whole Nine Yards, The Whole Ten Yards
in the second movie, you will get the picture, but the first movie is a must-see   :P

Where can I find the movies? Youtube?

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

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6262
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Visual Basic 2010/2013 and MASM
« Reply #14 on: July 11, 2014, 12:47:22 AM »
This is where the idea comes from.

“When I'm good, I'm very good, but when I'm bad, I'm better. ”

― Mae West

She was a master (Urrrgh Mistress) of brilliant one liners.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: