Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can someone please help me to convert the below given C language code to C# or VB.NET or any Microsoft Language? I need to use the functions written in this class from a ASP.NET website. Or Suggest me any other way to use the functions in my ASP.NET from from this C class.

C++
#include "qxdefs.h"

           #define MOD_ADLER 65521
           #define OVR_LIMIT 5550
           #define SIXTY4K 65536

           unsigned long a = 1, b = 0;
           int nc = 0;

           int fgl_init_checksum(int argc) {

             /*  re-initialize stuff:  */
             a = 1;
             b = 0;
             nc = 0;

             if(argc != 0)
               Abort("fgl_init_checksum()",1,-1318);

             return(0);  /* no fgl parameters to return */
           }
           /*
           #
           #
           #
           */
           void fold_down(void) {
             /* printf("before folding a = %X b = %X \n",a,b); */
             a = ( a & 0xffff ) + ( a >>16 ) * ( SIXTY4K - MOD_ADLER);
             b = ( b & 0xffff ) + ( b >>16 ) * ( SIXTY4K - MOD_ADLER);
             /* printf("after folding a = %X b = %X \n",a,b); */
             nc = 0;
           }
           /*
           #
           #
           #
           */
           int fgl_add_chk_string(int argc) {
             char str_in[201];
             int len;
             int i;
             unsigned char *data;

             if(argc != 1 )
               Abort("fgl_add_chk_string()",1,-1318);

             memset(str_in,' ',200); str_in[200]= 0;
             VarPop(SQLCHAR,str_in,sizeof(str_in)-1);
             len = ClipLen(str_in,sizeof(str_in));
             str_in[len] = 0; /* truncate to clipped length */
             /* Well,  I think we've got our parameter now.  That was painless wasn't it? */

             /* cast the string into a pointer to unsigned bytes */
             data = ( unsigned char * ) str_in;

             for ( i = 0; i<len;>                nc ++;
               if ( nc > OVR_LIMIT ) fold_down();
               a += *data++; /* not at all sure about that pointer stuff */
               b += a;
               /* printf("a = %d b = %d\n",a,b); */
             }
             return(0); /* no fgl parameters to return */
           }
           /*
           #
           #
           #
           */
           int fgl_checksum(int argc) {
             unsigned long n=0;
             char cs[21];

             if(argc != 0)
               Abort("fgl_checksum()",1,-1318);

             memset(cs,' ',20); cs[20]=0;

             if ( nc > 0 ) fold_down();

             if ( a >= MOD_ADLER )
               a -= MOD_ADLER;

             b = ( b & 0xffff) + ( b >> 16 ) * ( SIXTY4K - MOD_ADLER );

             if ( b >= MOD_ADLER )
               b -= MOD_ADLER;

             /* printf(" a = %X b = %X \n",a,b); */

             n = ( b << 16 ) | a;

             /* 4gl can't cope with an unsigned integer.  Once bit 32 gets set it
                thinks it's negative.  Return it as a Hex string */

             sprintf(cs,"%X",n);

             /* weird cargo cult code here. This is just cribbed from querix-
                generated code.  When I try to do what I think is a sensible
                version of this it doesn't work.  I'm guessing there are
                some odd side effects to ArgRet that I don't understand */

             StringPush(cs);
             status = VarPop(SQLCHAR, cs, 21, 0);
             VarPush(SQLCHAR, cs, 20, 0);
             status = ArgRet(1);
             if (status < 0)
             {
                 Abort("fgl_checksum", 16, status);
             }
             return(1);

           }
Posted
Updated 3-Oct-14 0:04am
v2
Comments
[no name] 3-Oct-14 6:02am    
We are not a code translation service. Converting C code to .NET doesn't make any sense anyway. Easier to rewrite it.
George Jonsson 3-Oct-14 6:20am    
This code is not really translatable, so it is better you try to define what it is you want to do, e.g. calculate a checksum, and then search for code in c# or VB.

This might be helpful: Adler-32 Checksum Calculation[^]
 
Share this answer
 
As already suggest, you'd better try to rewrite it from scratch (and, you know, C is a 'Microsoft language' too). In any case how could we help you without know without knowing what 'StringPush', 'VarPush', .. do?
Morevover it doesn't look a very robust piece of code (at least judging by the remarks :-) ).
Probably it would be simpler if you could tell us what's the purpose of such a piece of code.
 
Share this answer
 
I think you must search your question on code project. If you are sure that your question is not asked already by someone else, then you should post a new one.

You must read the below thread.

conversion c source code to c#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900