本文介绍了请帮我将下面给出的C语言代码转换为C#或VB.NET或任何Microsoft语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有人可以帮我将下面给出的C语言代码转换为C#或VB.NET或任何Microsoft语言吗?我需要从ASP.NET网站使用此类中编写的函数。或者建议我从这个C类中使用我的ASP.NET中的函数。 #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){ / * 重新初始化东西:* / a = 1 ; b = 0 ; nc = 0 ; if (argc!= 0 ) Abort( fgl_init_checksum(), 1 , - 1318 ); return ( 0 ); / * 没有要返回的fgl参数* / } / * ### * / void fold_down( void ){ / * printf(折叠前a =%X b =%X \ n,a,b); * / a =(a& 0xffff)+(a>> 16)*(SIXTY4K - MOD_ADLER); b =(b& 0xffff)+(b>> 16)*(SIXTY4K - MOD_ADLER); / * printf(折叠后a =%X b =%X \ n,a,二); * / 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 ; / * 截断到剪裁长度* / / * 好吧,我想我们现在有了参数。那是无痛的不是吗? * / / * 将字符串转换为指向无符号字节的指针* / data =( unsigned char *)str_in; for (i = 0 ; i< len;> nc + +; if (nc> OVR_LIMIT)fold_down(); a + = * data ++; / * 完全不确定那个指针的东西* / b + = a; / * printf(a =%db =%d \ n,a,b); * / } return ( 0 ); / * 没有要返回的fgl参数* / } / * ### * / 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 )|一个; / * 4gl无法处理无符号整数。一旦第32位被设置,认为它是负面的。将其作为十六进制字符串返回* / sprintf(cs, % X中,n); / * 奇怪的货物崇拜代码。这只是来自querix- 生成的代码。当我尝试做我认为合理的版本时,它不起作用。我猜猜有一些对ArgRet有些奇怪的副作用我不明白* / 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 ); } 解决方案 这可能会有所帮助:Adler-32校验和计算 [ ^ ] 正如已经建议的那样,你最好尝试从头开始重写它(而且,你知道, C 也是一种微软语言。在任何情况下,我们如何在不知道'StringPush','VarPush'的情况下如何知道帮助你呢? 此外,它看起来并不是一个非常强大的代码(至少可以判断为备注:-))。 如果你能告诉我们这段代码的目的是什么,可能会更简单。 我认为你必须在代码项目中搜索您的问题。如果您确定其他人没有提出您的问题,那么您应该发布一个新问题。 您必须阅读以下主题。 将c源代码转换为c# [ ^ 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. #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); } 解决方案 This might be helpful: Adler-32 Checksum Calculation[^]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.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#[^] 这篇关于请帮我将下面给出的C语言代码转换为C#或VB.NET或任何Microsoft语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 23:23