PDA

Click to See Complete Forum and Search --> : Making a .dll for vb...


Lord Orwell
Mar 2nd, 2001, 03:18 AM
I am not nearly as good a programmer in c++ as i am in vb. I would like to make a c++ .dll that does this:
it would incorporate the following in-line assembly:

Int 21h Function 440Dh Minor Code 61h (FAT32)
[Windows 95 only.]

Reads data from a track on the specified device and places the data in memory.

mov bx, Drive ;See below
mov ch, DeviceCat ;See below
mov cl, 61h ;Read track on logical drive
mov dx, seg ReadBlock ;See below
mov ds, dx
mov dx, offset ReadBlock ;ds:dx points to RWBLOCK structure
mov ax, 440Dh ;IOCTL for block device
int 21h

jc error_handler ;carry set means error

Parameters
Drive
Specifies the drive to be read from (0 = default drive, 1 = A, 2 = B, and so on).
DeviceCat
Specifies a FAT16, FAT12 or FAT32 drive. Value Description
08h FAT16 or FAT12 drive. (Will fail on a FAT32 drive).
48h FAT32, FAT16, or FAT12 drive. This value is supported on Windows 95 OEM Service Release 2 and later.

ReadBlock
Points to an RWBLOCK structure that contains information specifying the sectors to be read from. The RWBLOCK structure has the following form:
RWBLOCK STRUC
rwSpecFunc db 0 ;special functions (must be zero)
rwHead dw ? ;head to read/write
rwCylinder dw ? ;cylinder to read/write
rwFirstSector dw ? ;first sector to read/write
rwSectors dw ? ;number of sectors to read/write
rwBuffer dd ? ;address of buffer for read/write data
RWBLOCK ENDS

Basically, i want to make this in-line assembly into a function. If anyone can show me (or better yet, post the source code to do this) then let me know. I am trying to convert a program i wrote in dos that called interrupts, and have yet to be able to call interrupts with vb. A c++ dll can, however. If i just had a sub to read a disk sector, and another to write a disk sector, i would be in business.

If someone were to write the .dll for me, i would have no problem using them in the credits as a co-author. I plan on releasing the program as shareware. There could be a potential future financial gain in it for you.

The best design for the .dll would be one that would take one parameter for each register and one for the interrupt to call. That way, i could write sectors, etc. all with the same function.
Any takers?

Neandrake
Mar 6th, 2001, 02:22 PM
I've been experimenting with c++ dlls for vb. I currently use msvc++ to make them but anyone that has the capabilities should be fine. There is probably a different format in different compilers; I'm just now learning this and so I use msvc and a good book called "C++ For Vb Programmers" which explains also the making of a dll file for vb. First off, you need a .DEF file (i think needs to be the same name as .cpp file) with the following format:
------beginning of .def format sample--------------
LIBRARY (the dll filename)
DESCRIPTION "Description for the dll; I think this is optional"
EXPORTS
Function1
Function2
-----------end of sample---------------

Then you need a .cpp file(in vc++ there should be one already made with some code already in it)

the format for creating functions inside the cpp file for the dll are as follows:

---------beginning-----
long APIENTRY Function1(int num1, int num2) {
long NewVar;
NewVar num1 * num2 / (num2 - num1) + num1;
return NewVar;
}
---end---------

in the first line, the 'long' specifies what type of variable it's returning, if any; APIENTRY needs to come right afterwards; and the Function1 needs to be the same as in the DEF file. The num1 and num2 need to be provided in the call from VB as example:

----in a vb module------
Public Declare Function AlterNums Lib "Dllfile" Alias "Function1" (num1, num2) As Long
---------------
The AlterNums is the name of the function to use inside vb so you could do this:
AlterNums 21, 5
AlterNums Var1, Var2
and the "Function1" is the name of the function inside the dll file. If the Name inside the dll file is the same as the name to use inside Vb, it will remove the Alias to become:

Public Declare Function Function1 Lib "Dllfile" (num1, num2) As Long

However, I've been told you can not use interrupts inside the dll because they are DOS interrupts and can not be called in windows. However, you can use the asm block in cpp

_asm {
// CPP comments and Asm comments allowed
/*However, you will most likely get errors in the inline assembly. I forget what kind, but it's when using varibles inside the asm. If you do get the problems, email me and I'll give you a link to MSDN where they show corrections*/
}

parksie
Mar 6th, 2001, 03:01 PM
Public Declare Function AlterNums Lib "Dllfile" Alias "Function1" (num1, num2) As Long
You have to specify the data type or things get a little hairy...

Lord Orwell
Mar 6th, 2001, 04:40 PM
I was thinking that the functions in int21 i listed were windows specific. It should work if it will work with inline assembly. Because it is called exactly the same way. Load the registers, call the interrupt. I just want to load the registers from a variable instead of a constant like in the code.
the only data i am really interested in is the ability to read and write sectors. This functionality doesnt exist in the api createfile() in win 95/98/me for some reason.

Neandrake
Mar 6th, 2001, 09:00 PM
Do you think you would be willing to share information on Disk Sector reading, writing? I've been trying to find info on it, but all I found was something about CHS(I believe) and Interrupt 13h. Any information on how to get/set data to sectors of disk would be greatly appreciated. Thanks!

Lord Orwell
Mar 6th, 2001, 10:24 PM
Well the above information i posted is it. The original post has all the information about reading this way. The only other way to read is to make a virtual device driver. I copied the info directly from the msvc++ help file. It is supposed to be used with inline assembly.
You pass it head #, track#, sector #, etc. (which you come up with by reading the disk parameters with another api call - getdriveinfo i think, which gives youthe max value of each). You also give it a null-terminated string buffer to fill with the data to read.

Neandrake
Mar 7th, 2001, 01:53 PM
you just want to know how to put it in dll form? Is it for VB or c++?

Neandrake
Mar 7th, 2001, 02:30 PM
Scratch my last post, forgot to look at the main topic. Do you happen to have AOL (Instant Messanger). I prefer to IM rather than take up alot of Board space. I was trying to make something that could write to sectors of a disk but was insuccessful. I found some c code which supposedly does it, but it's very small(12 lines of code) and I don't clearly understand it (not too much of a c/c++ user yet).

parksie
Mar 7th, 2001, 02:33 PM
What's the code?

Neandrake
Mar 7th, 2001, 02:41 PM
Got this at the Operating Systems Resource Center

//***************START****************
#include <bios.h>
#include <stdio.h>

void main()
{
FILE *in;
unsigned char buffer[520];

if((in = fopen("bootsect", "rb"))==NULL)
{
printf("Error loading file\n");
exit(0);
}

fread(&buffer, 512, 1, in);

while(biosdisk(3, 0, 0, 0, 1, 1, buffer));

fclose(in);
}
//*************END****************************

parksie
Mar 7th, 2001, 02:46 PM
That's plain C :)

PS: Use [ php ] [ /php ] tags to format C/C++ code.

Lord Orwell
Mar 7th, 2001, 07:54 PM
I was wanting a c++ dll capable of being called from vb because it is impossible to read sectors of a disk from vb, even with api calls (unless you use win nt)

Lord Orwell
Mar 10th, 2001, 03:05 PM
resetting post...