Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Converting vb codes to C

 Open App.Path & "\test" For Binary Access Read As #1
    lngSize = LOF(1)
    If lngSize <> 204855 Then
      MsgBox "The exe has been tempered. Active failed !", vbInformation, "Error"
      Exit Function
    End If
    Get #1, , arryByte
  Close #1
  arryByte(1001) = arryByte(1001) + 100

  Open App.Path & "\test" For Binary Access Write As #2
    Put #2, , arryByte
  Close #2

Above is my VB codes. Can experts help me out to convert
it into C program ?

Thanks !
  • 2
1 Solution
Roshan DavisCommented:
This is a rough work, may be have simple errors,
 Try it

#include <stdio.h>
#include <malloc.h>

void main( void )
   FILE *stream;
   int fhandle;
   int filesize;
   char *pchArrayByte;

   if( (stream = fopen( "test", "r" ))  )
          // get handle to the file and determine file size
          fhandle = fileno(stream);
          filesize = filelength(fhandle);

          if ( 204855 != filesize )
               printf("The exe has been tempered. Active failed !");

          pchArrayByte = (char*)malloc(204855);

          numread = fread( pchArrayByte, sizeof( char ), 204855, stream );


          pchArrayByte[1001] += 100;

          if( (stream = fopen( "test", "w" ))  )
               fwrite( pchArrayByte, sizeof( char ), 204855, stream );

tryforumAuthor Commented:
Let me test it out and will let you know ! Thanks
Roshan DavisCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now