DLL Query

Hi All,

I have written a DLL (in C++) which is supposed to return the CRC (16) of a string. It seems to work fine when included as part of a Visual C++ program (not a DLL), but when I make it a DLL and call it from progress I get the wrong numbers returned. And it is a different number every time. I will list the Progress code below and also the C++ code and see if something jumps out at anyone as being wrong. I think it has something to do with the way I am returning the CRC, as in the project I wasn't actually returning it because it is memory pointer and therefore didn't need to be returned.

Progress code:
/*
I am using this file simply to test my CRC16 dll functionality
*/

def var vString as char no-undo format "X(20)".
def var vChar as char no-undo.
def var vCRC as int no-undo.
def var vLength as int no-undo.
def var vCount as int no-undo.


update vString.

vLength = length(vString).
vCRC = 0.

do vCount = 1 to vLength:

vChar = substring(vString,vCount,1).

run CheckCRC (input vCRC,
input vChar ,
output vCRC).

end.
message "CRC returned was " + string(vCRC) view-as alert-box.

procedure CheckCRC external "CRC16.dll":
def input param ipCRC as short no-undo.
def input param vChar as char no-undo.
def return param opCRC as short no-undo.
end procedure. /* CheckCRC */



C++ Code:
/********************************************************************
* Filename: CRC16
* Version: 1.0
*
* Date of Creation: 24/11/2000
* Author: Wayne Singh
* Description: Calculates CRC-16 for Character
*
* Input: - Current CRC value (unsigned short)
* - Next character in string (char)
*
* Output: - New CRC value (unsigned short)
*
********************************************************************/
#include <windows.h>

extern "C" unsigned short _declspec(dllexport) WINAPI CheckCRC(unsigned short *CRCWord, char character)
{
unsigned int vCtr;
unsigned int carry;
char x16;
unsigned int value;

value = int (character);

for (vCtr = 0; vCtr < 8; vCtr++) {

x16 = (value & 1) ^ (*CRCWord & 1);

value = value >> 1;

if (x16 == 1) {

*CRCWord = *CRCWord ^ 0x4002;

carry = 1;
}
else if (x16 != 1) {
carry = 0;
}

*CRCWord = *CRCWord >> 1;

if (carry == 1) *CRCWord = *CRCWord | 0x8000;

else if (carry == 0) *CRCWord = *CRCWord & 0x7fff;
}

return(*CRCWord);
}


The progress code is a little sloppy, but it is only for testing purposes. The string I have been testing it with is #POL0040101, which should return a value of 49116, or BF DC (Hex). Please if anyone can help it would be really appreciated. Maybe there is some way to return the pointer value without having to actually pass the physical value back to Progress (I haven't given the best explanation have I).
I have been working on this for a fair while now and am starting to get the S**ts with it!

Thank you in advance to anyone who can help me.

Wayne Singh
 
Top