这个C++函数如何翻译成Delphi? ( 积分: 100 )

  • 主题发起人 主题发起人 DelphiCoding
  • 开始时间 开始时间
D

DelphiCoding

Unregistered / Unconfirmed
GUEST, unregistred user!
int&nbsp;&nbsp;&nbsp;__stdcall&nbsp;&nbsp;&nbsp;BCode2SCode_3(char&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;const,&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;const,&nbsp;&nbsp;&nbsp;int,&nbsp;&nbsp;&nbsp;int);&nbsp;<br><br>这个函数如何声明成Delphi格式?
 
function&nbsp;BCode2SCode_3(const&nbsp;v1,&nbsp;v2:&nbsp;PChar;&nbsp;int1,&nbsp;int2:&nbsp;integer):&nbsp;integer;&nbsp;StdCall;
 
我是这样翻译的啊<br>但是结果好像不对哦<br>我传递什么参数进去返回结果都是-1
 
type<br>&nbsp;&nbsp;PPChar:&nbsp;^PChar;<br><br>function&nbsp;BCode2SCode_3(const&nbsp;c1:&nbsp;PChar;&nbsp;const&nbsp;c2:&nbsp;PPChar;&nbsp;i1,&nbsp;i2:&nbsp;Integer):&nbsp;Integer;&nbsp;stdcall;
 
static&nbsp;unsigned&nbsp;int&nbsp;crctab[256]&nbsp;=<br>{<br> 0x0000,&nbsp;0x1021,&nbsp;0x2042,&nbsp;0x3063,&nbsp;0x4084,&nbsp;0x50A5,&nbsp;0x60C6,&nbsp;0x70E7,<br> 0x8108,&nbsp;0x9129,&nbsp;0xA14A,&nbsp;0xB16B,&nbsp;0xC18C,&nbsp;0xD1AD,&nbsp;0xE1CE,&nbsp;0xF1EF,<br> 0x1231,&nbsp;0x0210,&nbsp;0x3273,&nbsp;0x2252,&nbsp;0x52B5,&nbsp;0x4294,&nbsp;0x72F7,&nbsp;0x62D6,<br> 0x9339,&nbsp;0x8318,&nbsp;0xB37B,&nbsp;0xA35A,&nbsp;0xD3BD,&nbsp;0xC39C,&nbsp;0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13,&nbsp;0x2E32,&nbsp;0x1E51,&nbsp;0x0E70,<br> 0xFF9F,&nbsp;0xEFBE,&nbsp;0xDFDD,&nbsp;0xCFFC,&nbsp;0xBF1B,&nbsp;0xAF3A,&nbsp;0x9F59,&nbsp;0x8F78,<br> 0x9188,&nbsp;0x81A9,&nbsp;0xB1CA,&nbsp;0xA1EB,&nbsp;0xD10C,&nbsp;0xC12D,&nbsp;0xF14E,&nbsp;0xE16F,<br> 0x1080,&nbsp;0x00A1,&nbsp;0x30C2,&nbsp;0x20E3,&nbsp;0x5004,&nbsp;0x4025,&nbsp;0x7046,&nbsp;0x6067,<br> 0x83B9,&nbsp;0x9398,&nbsp;0xA3FB,&nbsp;0xB3DA,&nbsp;0xC33D,&nbsp;0xD31C,&nbsp;0xE37F,&nbsp;0xF35E,<br> 0x02B1,&nbsp;0x1290,&nbsp;0x22F3,&nbsp;0x32D2,&nbsp;0x4235,&nbsp;0x5214,&nbsp;0x6277,&nbsp;0x7256,<br> 0xB5EA,&nbsp;0xA5CB,&nbsp;0x95A8,&nbsp;0x8589,&nbsp;0xF56E,&nbsp;0xE54F,&nbsp;0xD52C,&nbsp;0xC50D,<br> 0x34E2,&nbsp;0x24C3,&nbsp;0x14A0,&nbsp;0x0481,&nbsp;0x7466,&nbsp;0x6447,&nbsp;0x5424,&nbsp;0x4405,<br> 0xA7DB,&nbsp;0xB7FA,&nbsp;0x8799,&nbsp;0x97B8,&nbsp;0xE75F,&nbsp;0xF77E,&nbsp;0xC71D,&nbsp;0xD73C,<br> 0x26D3,&nbsp;0x36F2,&nbsp;0x0691,&nbsp;0x16B0,&nbsp;0x6657,&nbsp;0x7676,&nbsp;0x4615,&nbsp;0x5634,<br> 0xD94C,&nbsp;0xC96D,&nbsp;0xF90E,&nbsp;0xE92F,&nbsp;0x99C8,&nbsp;0x89E9,&nbsp;0xB98A,&nbsp;0xA9AB,<br> 0x5844,&nbsp;0x4865,&nbsp;0x7806,&nbsp;0x6827,&nbsp;0x18C0,&nbsp;0x08E1,&nbsp;0x3882,&nbsp;0x28A3,<br> 0xCB7D,&nbsp;0xDB5C,&nbsp;0xEB3F,&nbsp;0xFB1E,&nbsp;0x8BF9,&nbsp;0x9BD8,&nbsp;0xABBB,&nbsp;0xBB9A,<br> 0x4A75,&nbsp;0x5A54,&nbsp;0x6A37,&nbsp;0x7A16,&nbsp;0x0AF1,&nbsp;0x1AD0,&nbsp;0x2AB3,&nbsp;0x3A92,<br> 0xFD2E,&nbsp;0xED0F,&nbsp;0xDD6C,&nbsp;0xCD4D,&nbsp;0xBDAA,&nbsp;0xAD8B,&nbsp;0x9DE8,&nbsp;0x8DC9,<br> 0x7C26,&nbsp;0x6C07,&nbsp;0x5C64,&nbsp;0x4C45,&nbsp;0x3CA2,&nbsp;0x2C83,&nbsp;0x1CE0,&nbsp;0x0CC1,<br> 0xEF1F,&nbsp;0xFF3E,&nbsp;0xCF5D,&nbsp;0xDF7C,&nbsp;0xAF9B,&nbsp;0xBFBA,&nbsp;0x8FD9,&nbsp;0x9FF8,<br> 0x6E17,&nbsp;0x7E36,&nbsp;0x4E55,&nbsp;0x5E74,&nbsp;0x2E93,&nbsp;0x3EB2,&nbsp;0x0ED1,&nbsp;0x1EF0<br>};<br><br>WORD&nbsp;&nbsp;CalCRC(const&nbsp;BYTE&nbsp;*lpData,&nbsp;DWORD&nbsp;nLen)<br>{<br> if(NULL==lpData)<br> return&nbsp;0;<br> WORD&nbsp;nCRC=0;<br> BYTE&nbsp;da;<br> while(nLen--!=0)<br> {<br> da&nbsp;=&nbsp;(BYTE)(nCRC/256);<br> nCRC&nbsp;&lt;&lt;=&nbsp;8;<br> nCRC&nbsp;^=&nbsp;crctab[da^(*lpData)];<br> lpData++;<br> }<br> return&nbsp;nCRC;<br>}<br>转成DELPHI?
 
zqw0117,&nbsp;是正确的。
 
标准调用添加stdcall关键字,至于指针,这个要加^,但是这种死板的转换毕竟很多时候编译过了运行不过,具体要看函数完成什么功能和他的方法!我们提倡翻译思想和方法,不是单纯的翻译代码,毕竟不同的语言还是对于定义,调用都不一样,要不还要这么多语言干嘛?<br><br>这个道理和英语和中文的死板翻译是一个道理:<br>how&nbsp;old&nbsp;are&nbsp;you?<br>多大年龄是你的?//死板翻译<br>意译:你多大年龄?
 
楼上的翻译有问题,应该是这样:<br><br>how&nbsp;are&nbsp;you&nbsp;<br>怎么&nbsp;是&nbsp;你<br>how&nbsp;old&nbsp;are&nbsp;you&nbsp;&nbsp;<br>怎么&nbsp;老&nbsp;是&nbsp;你
 
const<br>&nbsp;&nbsp;&nbsp;crctab&nbsp;:&nbsp;array[0..255]&nbsp;of&nbsp;Longword =&nbsp;(<br>&nbsp;$0000,&nbsp;$1021,&nbsp;$2042,&nbsp;$3063,&nbsp;$4084,&nbsp;$50A5,&nbsp;$60C6,&nbsp;$70E7,<br>&nbsp;$8108,&nbsp;$9129,&nbsp;$A14A,&nbsp;$B16B,&nbsp;$C18C,&nbsp;$D1AD,&nbsp;$E1CE,&nbsp;$F1EF,<br>&nbsp;$1231,&nbsp;$0210,&nbsp;$3273,&nbsp;$2252,&nbsp;$52B5,&nbsp;$4294,&nbsp;$72F7,&nbsp;$62D6,<br>&nbsp;$9339,&nbsp;$8318,&nbsp;$B37B,&nbsp;$A35A,&nbsp;$D3BD,&nbsp;$C39C,&nbsp;$F3FF,&nbsp;$E3DE,<br>&nbsp;$2462,&nbsp;$3443,&nbsp;$0420,&nbsp;$1401,&nbsp;$64E6,&nbsp;$74C7,&nbsp;$44A4,&nbsp;$5485,<br>&nbsp;$A56A,&nbsp;$B54B,&nbsp;$8528,&nbsp;$9509,&nbsp;$E5EE,&nbsp;$F5CF,&nbsp;$C5AC,&nbsp;$D58D,<br>&nbsp;$3653,&nbsp;$2672,&nbsp;$1611,&nbsp;$0630,&nbsp;$76D7,&nbsp;$66F6,&nbsp;$5695,&nbsp;$46B4,<br>&nbsp;$B75B,&nbsp;$A77A,&nbsp;$9719,&nbsp;$8738,&nbsp;$F7DF,&nbsp;$E7FE,&n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p;&nbsp;Inc(lpData)&nbsp;;<br>&nbsp;&nbsp;end&nbsp;;<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;nCRC&nbsp;;<br>end;
 
Function&nbsp;BCode2SCode_3(Param1&nbsp;:&nbsp;PChar;&nbsp;Param2&nbsp;:&nbsp;PPChar;&nbsp;Param3,&nbsp;Param4:Integer):Integer;stdcall;
 
后退
顶部