Results 1 to 3 of 3

Thread: COnvert C coding to VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    9

    COnvert C coding to VB

    Hello. Can anybody convert this C coding to VB? This coding is to read location to obtain addresses of my printer port. Also , i have this algorithm so that when my IR sensor is triggered, (connected to parallel port in my PC) it will also triggered my web camera to capture picture(connected to usb port) but i dont know how to write it in VB. Thanks in advance

    The C coding need to convert to VB
    #include <stdio.h>
    #include <dos.h>

    void main (void)
    {
    unsigned int far *ptraddr ; /*pointer to location of Port Adress*/
    unsigned int address ; /* adress of port*/
    int a:

    ptraddr=(unsigned int far *) 0x00000408;

    for (a=0;a<3;a++)
    {
    address = *ptraddr;
    if (address ==0)
    printf ("No port found for LPT5d \n, a+1);
    else
    printf ( "Adress assigned to PLT&d is %Xh\n", a+1, address);
    *ptraddr++;
    }
    }

    The algo needed to write in VB

    Initialize base address, pin...etc

    Read the parallel port
    Is Bit0 = 0 /*If yes, loop again upper line and this line
    /*If No, continue

    Read parallel port
    Is Bit0=1 /*If yes, loop again this statement
    /*If no continue

    Initiate code to detect camera
    Make camera capture picture

    End

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: COnvert C coding to VB

    You can't directly access protected memory in a Windows app like you could in old DOS apps.

    To see what I mean, create a new form with a TextBox and use this code.
    VB Code:
    1. Option Explicit
    2. Private Declare Sub CopyMemory Lib "KERNEL32" _
    3.                     Alias "RtlMoveMemory" (hpvDest As Any, _
    4.                                            hpvSource As Any, _
    5.                                            ByVal cbCopy As Long)
    6.  
    7. Private Sub Form_Load()
    8.   Dim ptraddr As Long
    9.   Dim address As Long
    10.   Dim i       As Integer
    11.  
    12.   ptraddr = &H408&
    13.   For i = 0 To 2
    14.       CopyMemory address, ByVal ptraddr, 4
    15.       If address = 0 Then
    16.          Text1.Text = Text1.Text & _
    17.                       "No port found for LPT" & (i + 1) & vbCrLf
    18.       Else
    19.          Text1.Text = Text1.Text & _
    20.                       "Address assigned to LPT" & (i + 1) & _
    21.                       " is " & address & vbCrLf
    22.       End If
    23.       ptraddr = ptraddr + 4
    24.   Next i
    25.  
    26. End Sub
    Set a breakpoint at the For statement so that you get a chance to see the error message, otherwise the IDE just gets blown away when the first CopyMemory executes.

    You may be able to find an API to access the printer ports.

  3. #3
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width