Yep... "Toy 4 Dummies"... So, this here is a VB6 Add-In that runs silently in the background and makes it possible to add functions coded in Assembly Lang. directly to VB projects. No preprocessing of the ASM code is necessary unlike the CallWindowProc method. It does require MASM to do the compile at build time. There is no way to use VB's native compiler to do this. It just is not possible. There are other restrictions as well. They are documented in the ReadMe.txt file. Instructions on set-up are also in the ReadMe as well as an URL to a site to get MASM. I've included a few test projects and a couple of tutorials. Have to Upload in a different zip cuz PSC is rejecting the zip with everything. The String project was not as successful as I would have liked, but then, I've learned just enough ASM to be really dangerous 8~). Special thanks to Robert Rayment for the ASM projects he's shared in the past. Those VBP's were a big help in getting this debugged and running properly as well as increasing my ASM knowledge..... Tested and working with VB6 on Nt4 & W2K. Previous problems and crashes are documented in the ReadMe.txt so if you have a problem check there first...◙
BugzFixed (zip updated): ◙
ML.exe not found-> TextCompare ◙
Commandline modify crashing VB ◙
LongFile name spaces not recognize in ML cmdLine ◙
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
Re-scan downloaded files using your personal virus checker before using it.
NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net
Terms of Agreement:
By using this code, you agree to the following terms...
You may use
this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this code from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
If you're a person who only reads the instructions as a last resort, to get this project to work you MUST have MASM (ml.exe) and you MUST set the add-in to the path of that file (ml.exe) after you compile the add-in dll and load it with Add-in manager.... Enjoy. (If this comment was disrespectful, please report it.)
Pretty cool, I must say. BUT there is one bug that will definetly need a fix :). All your "ml.exe" checks are binarycompare, capital sensitive. Not, if I have "Ml.exe", or "ML.exe", instr will NOT be 0, thus giving the "assembler path not set" error.
One solution is to compare everything lowercase, or to use: Instr(1,path,"ml.exe",vbTextCompare) <> 0
I just got it working. Now time to try some stuff :) (If this comment was disrespectful, please report it.)
btw. I have to add that this might be very cool :). You know, I once did something similar, saved the generated code, and then modify it by hand for example, replacing the Ucase$() function.. making it LOTS faster :) (If this comment was disrespectful, please report it.)
Good..Smells me like TweakVB (Even # $ tags)..John. Peoples must be familiar with Local & Global variable declaration like: call DWORD PTR __imp____vba@001CCD08 or mov eax, DWORD PTR _XYZVARIABLE$[ebp] (variable on stack/base)...
Conclusion: You must be very well with RC2 compiler to do the job with in-line-Assembler!
Anyway,good job.But not for the VB Peoples instead! (If this comment was disrespectful, please report it.)
Agree.... This is not for the average VB'er. Just look at 90% of the code posted to PSC will tell'ya that. If I could have rated it "Super Advanced", I wood'a.... but wanted to share it with that 10% PSC "Cream of the Crop"....8~). Not sure how close it is to TweakVB since I've never used that prog. (If this comment was disrespectful, please report it.)
All.. Thanks for pointing out the TextCompare bug. I did all the dev and testing with only the "ml.exe" even though I have "Ml.exe" in a diff. dir. With a quick test, switching between different "ml.exe"'s, I had to shut down VB and restart to get the new path recognized for a compile but most won't be affected by that.... I'll look into it "One of these days".... I've added the Option Compare Text to the project mods. and replaced the original zip. Add a couple of the test projects to this zip also since some people may not realize that there is a 2nd zip with test vbp's to DL... The 2nd zip still includes more than this one does so DL that too if interested.... (If this comment was disrespectful, please report it.)
Hmm, one question though. I simply cannot get CPUID instruction to work? Everytime I get a syntax error (in the masm debug log), while I'm doing everything correct.. ? Just wondering :). I'm used to NASM inbstead of MASM, so that miht be the cause as well.. which makes me wonder if it's possible to use the nasm compiler as well in a later version? :) (If this comment was disrespectful, please report it.)
Almar, in the debuglog for the MASM output, the MASM error will give the line # of the error. It is always in parenthesis... eg. (234) Would mean the error is on line 234 of the ASM file. Of course you will need an editor that tracks the line numbers.... NotePad won't get it.... Little differences between the ASM compilers will cause errors... I had MANY when converting Robert's code for use with MASM. BTW, MASM will stop listing errors when the amount of errors exceeds 100... (VBG). (If this comment was disrespectful, please report it.)
Well, I gave up on the CPUID instruction, but I cannot seem to get "fild" working either... I get "error A2023: instruction operand must have size" everytime. Fro mthe generated .asm file: (at top) long1 equ [ebp-4] (code) fild dword long1
(If this comment was disrespectful, please report it.)
OK... That "cpuid" instruction was little bit harder. Gives syntax err. Can't find any reference in the MASM ref. guide. Found a few .asm's using a Macro tho. I didn't put together a whole routine 2C if this works but this compiles and don't crash. Will it work 4U...???
'#ASM_START 'LONG1 EQU [EBP-4] ' 'CPU_ID MACRO ' db 0fh ' db 0a2h 'ENDM 'fild dword ptr long1 'mov eax,1 'CPU_ID 'ret 4 '#ASM_END (If this comment was disrespectful, please report it.)
Great, thanks. I thought PTR was for pointer only.. well, seems not. I created a simple GetDistance() function now, which uses fild, fsqrt and fistp.. works like a charm. Haven't tried the CPU info thing yet. Will do tommorow :)
I wish I could vote more for you. It's great. (If this comment was disrespectful, please report it.)
I haven't looked at MMX yet, but I might do now. I just finished my SinCos() function which uses fSinCos, which is 50% faster than using VB's Sin/Cos seperatly :) (If this comment was disrespectful, please report it.)
Yep, 1st timing call always includes load time. Have to chk out the "DoNothing".... Or just put the VB 1 first 8~)
I tried to get the "INVOKE" statement to work be failed on that too. Spent better part of a day. Prob. was the includes were having err's and I was in no mood to go thru all the code in the windows.inc to fix it.... But since you've mentioned the ".586" I'm wondering if that might do the trick. Have to chk it out this weekend.
On the high level stuff... I read somewhere that it is slower than using the basic asm instructions... Ran across it while looking for String routines. (If this comment was disrespectful, please report it.)
lol :D. I did the same thing today :D. I got it to compile though, first, I removed /Zm from the plugin, where it calls "ml.exe". all those windows errors were fixed. Then, I got some other errors, and this is where the tricky part comes :). In the generated ASM, you have to change .model line to ".model flat, stdcall". Now there might be a few errors, which are caused by some variable things, but those can easily be solved. I got it to compile the "popup" example of the Masm examples1 directory, but it does not work for me. If I press my command button which calls that sub, simply nothing happens. Odd thing is too that I cannot find the string constant which that code uses, back in the exe file. I know it compiled. First it gae some library errors, I changed the path so it had a drive prefix, and then no errors at all.. it seamed to compile just fine.
(If this comment was disrespectful, please report it.)
btw, don't change windows.inc, I know it gives errors first at line !14438 or something..if you change it, lot of the same errors will popup as well :) (If this comment was disrespectful, please report it.)
And U know, if you .bat compile one of those Win32 MASM32 examples it builds EXE that works fine... I tried the Example2\Bmbutton... had 8 .inc's and 7 .lib's, Windows.inc was included...??? So who knows, could just be a "VB" thing...LOL. I've had a few goofy compiles too... And if I remember correctly it was when I removed the /Zm switch from the cmdLine. No errors but it just wouldn't work... Go figger... As U R finding out, endless experimentation. Lots-O fun for HardCore Progging Geeks. 8~)
Not sure how far you've gotten in using the add-in options, but all the cmdLine mods, ASM file mods etc. can be made without changing any code in the add-in itself. Though I'd give it a mention "just in case"... I probly could have wrote a book on the detailed use of it. 8~) Tried to cover a good bit in the readme, tutorials and test projects.... (If this comment was disrespectful, please report it.)
Well, I spent (too much) time today on some string functions. I can't create a string in memory unfortunatly, and give it to VB. I'll skip that one. But, I did manage to port some Ucase code, which is lightning fast:
Almar, try this and let me know what happens: Check the "Modify cmdLine" option, compile, keep clicking the "Cancel" button until compile ends. Does it crash on that? When it does crash, is it on the first cmdLine that comes up or is it a specific module?
Can you "Pause the Build" OK? (If this comment was disrespectful, please report it.)
Ok... Almar, I can do it tooo... Upped a new zip or it is an easy fix. Took a bit to find cuz I thought it was something wrong with the cmdLine but it is in the form. Goto frmAddin.cmdSave_Click(). The last line in that sub is "if fCloseWindow then...", move that to under "Case 2", after line "If iTemplateIndex...". All is better.... (If this comment was disrespectful, please report it.)
Oh MY!!! 8~) Once ya get the hang of this, it can be too much fun (vbg).
I just got the first MMX routine running with modifcations to pick up those last bytes.... First by DWORD, then the remainer with BYTE. In the MemCopy test project I was getting around .04 sec. for the org. 3 functions.... this is giving me .03 sec.... NICE!!! Going to try the others later in between some other stuff I have to get too. LOL....
Almar, if you send me your email addr. I'll send you the code... PSC screws up the text formating to much to try it here.... Guess I could up another TestProjects zip "One of These Days".... But I can just send you the code 4 now. (If this comment was disrespectful, please report it.)
Got the 3rd to run (PreFetch). Not much speed difference with the 2nd. The last (4th) one with the Streaming Read/Write only crashes 4 me. I did code the PreFetch in both 64b & 128b ver's. Started running into problems with the 128b stuff. The Dev. box is NT4-800MHz Duron and it crashes on the 128b. W2K box is 667MHz Celeron and it will run it. The 128b did time faster by a little. So when getting into 128b both the CPU and the OS need to be just right. MASM 6.15 is compiling it OK. Will have to upgrade my CPU flag checker routine to expose all the flags and get a better idea of what is what.... From W2K box: Copy 5Mb using Api CopyMemory. 2.2373 sec
Copy 5Mb using ASM MemCopyMMX. 2.1729 sec
Copy 5Mb using ASM MemCopyMMX_NonTmp -> NON Temporal Stores. 1.2496 sec
Copy 5Mb using ASM MemCopyMMX_PreFetch -> PreFetch Ops. 1.1784 sec
Copy 5Mb using ASM MemCopyMMX_PreFetch128 -> 128b PreFetch 1.1614 sec (If this comment was disrespectful, please report it.)
I just want to say... wow. This is so cool! Anything that elevates VB above the so-called "Beginner's tool" so many people think it is is a god-send. Now if only we could ditch the runtimes :P
Anyway, I have a problem: I read above Almar was having trouble getting code to run; I have that same problem. I've tried both the math sample and string samples provided with the .Zip, and even after a full compile, shut down VB, run EXE just to be sure, the ASM routines never do anything (return 0 or blank values). Yes, I have the add-in hooked, I have latest version of ml.exe (6.15 or something from the VC6 processor pack), I checked the logs and no errors, it's definetly generating .asm files and listings, and yet it just won't work. Also, in case it's that, I'm running Win2k w/ VB6SP5. If there's anything else you need to know, lemme know; I really want this to work :)
(BTW: 5 globes; wish I could give you more :D) (If this comment was disrespectful, please report it.)
Daniel, thanks for the comments. "ditch the runtimes"... I have pondered that too. I thought many times about how to maybe go into a dll the extract the bytes and add them to the VB exe.... Yaaa, Dreams...
I've had the no ASM compile happen lots and it is "usually" fixed by a shut down and restart. BTW, what type of processor does your computer have?
I just tested it on my W2kVb6Sp5 and it is working OK. Make sure the option "output asm messages to log" is checked. If the add-in is hooked the toolbar icon should be in color also. This shouldn't have any effect but is the path to your MASM including spaces " "? (If this comment was disrespectful, please report it.)
Next: Did you DL the other zip with just test projects in it? In there is a dir ->PausingTheBuild. It is the simplest project in the bunch with only 1 asm function "Testing". Open that vbp and compile the exe, (making sure the addin is hooked etc). Run the exe, click the button, what happens. If you get a msgbox with zero return then "Houston, we GOT a problem..." 8~) It will be hard for me to say exactly what is wrong with out having your computer... Take a look at the "VbInlineAsm.dbg" and see if the MASM is outputing. it should have "Assembler Output @" and stuff like the MASM version #. If not ml.exe is not running. Next try adding a comma to the "Testing" function like this: "mov ,eax", save the file, then compile. You should get a compile error. Let me know what happens. (If this comment was disrespectful, please report it.)
Now, yes, ml.exe was in E:\Program Files\Microsoft Visual blah blah, so I dropped it into E:\bin instead.
Also, I turned all the logging options on to full, tried to compile that PauseBuild one... and got that rudding Floating Point Inexact error again. Grr. Shut it down, opened it back up again, and tried again; ok, everything worked... seemingly. Ran the .EXE, and again, the result was 0. I then tried modifying the ASM code as you suggested... either "wassup???:P:P" is a valid opcode, or ML's just not running... I think I'll go with the later ;)
Anyway, I'm going to try rebooting my machine totally (not pleasant due to the length of time it takes :P -- I just hibernate every night), and get back to you if it works or otherwise... Thanks for all your help... (If this comment was disrespectful, please report it.)
BTW; as for ditching the runtimes, I'm currently working on porting VB's methods (done VBA.Math and most of VBA.Strings thus far) to ANSI C++. Maybe one day it'll be complete enough that we can replace cl2.exe with a VB to C++ converter, and then call VC's cl.exe instead (drools at though of inline C++/ASM code :D) (If this comment was disrespectful, please report it.)
(Beats self about head) I found it... took a poke around the files that were being generated, and the line in the .dbg file was interesting: "Could not open file Source"... uh oh...
I've played with long filenames for long enough to know what that means... I checked the command line and there it was: it was trying to assemble the file E:\Personal\Files\Planet Source Code\Visual Basic\Vb etc. etc.asm, but of course it's going to chop off the filename at the \Planet bit, hence why it wasn't working. Once I copied it to a directory with no spaces, it worked perfectly... Although I know you can just surround the .asm file argument with double quotes (just check for spaces), how applications handle spaces embedded in switches (like for the MAP file) I'm not too sure about... I'm going to play with it and see if I can get it to work... If worst comes to worst, I'll just tell it to use the DOS path for the directories :P
Thanks once again, and great code. (If this comment was disrespectful, please report it.)
>Spaces in the path<... I didn't think it would be that but ya just never know.(s) I try to keep them things out of all my work but when you let windows install something to "Program Files" all paths then have it. But then maybe I should do the dev in a dir with spaces then it would never get into the code in the first place...lol
For anybody reading this far down the comments, Daniel has sent me the fix for the bug he found and I updated the zip.... (If this comment was disrespectful, please report it.)
1/29/2003 5:52:44 AM:
could you port some asm encryption algos (maybe RSA?!! :D) to work with this... my skills are to basic to get anything that long to work. (If this comment was disrespectful, please report it.)
Well, I probly could... But then you wouldn't get any education outta it... 8~)
Start with the test projects, study them, see how its done and then work your way up. Just about any MASM code will *almost* drop right in. And the MASM compile output in the debug log will tell you where any errors are... (If this comment was disrespectful, please report it.)
1/30/2003 3:33:18 AM:
problem is not so much geting it to compile... but useing vb strings in asm... and stuff like that... and the rsa encryption asm source i have has lots and lots of things i dont know what they do... let alone witch ones i need to use... (If this comment was disrespectful, please report it.)
Well, start reading up about ASM and learn what they do.... Or if you want me to do all the work you can sign a contract with me, I charge $100 hour, 5 hours minimum. Paid in advance with cashiers check. Be thankful that I'm giving away the source code for this add-in and not charging for it..... I've got 100's and 100's of hours into it.... (If this comment was disrespectful, please report it.)
Hmmm... where exactly is the add-in? The zip file contains 8 folders, but not the add-in (2 of the folders are tutorials and the remaining 6 are examples). (If this comment was disrespectful, please report it.)
Hm, my link to the plugin got deleted :(. Well, anyway. I fixed the problem myself why the code is not working for most people. Like the original author said "LongFile name spaces not recognize in ML cmdLine"
Exactly! Search line 375 from "MVBInlineASM.bas" and surround sFileName$ with Chr$(34). Same for the line above. And now it works with long paths :) :).
(If this comment was disrespectful, please report it.)
5/31/2005 7:19:24 AM:
You can download the add-in at http://www.persistentrealities.com/vbfibre/index.php until the link here is fixed. (If this comment was disrespectful, please report it.)
works nice, but am having trouble disabling int21 using asm. compiles fine, but when debugged in delphi 7 get error "priviledged instruction at..." using asm -> in al,21h or al,02 out 21h,al
btw - 5* from me!!!!! (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular code, please
click here instead.)