News:

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

Main Menu

Visual Basic 2010/2013 and MASM

Started by David BS, July 09, 2014, 03:27:19 PM

Previous topic - Next topic

David BS

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

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

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

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--

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.

dedndave

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

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

Quote from: David BS on July 10, 2014, 12:34:08 AM
And thank all of you for help and support. You're bad!

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

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

jj2007

Quote from: David BS on July 09, 2014, 11:46:58 PMI 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

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--

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:

Gunther

Quote from: David BS on July 10, 2014, 04:29:04 PM
Just seizing the opportunity: can EasyCode work with YASM?

You should ask that question here.

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

dedndave

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

Hi Dave,

Quote from: dedndave 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

Where can I find the movies? Youtube?

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

hutch--

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.