Hi,
I am quite new to C++ and I my code crashes after exiting the function in this place of "mlock.c" file:
void __cdecl _unlock (
int locknum
)
{
LeaveCriticalSection( _locktable[locknum].lock );
}
My function looks like this and should return false:
bool cCardClientNewCamd::SendMessage(const unsigned char *data, int len, bool UseMsgId, const struct CustomData *cd, comm_type_t commType)
{
...........
return true;}
bool cCardClientNewCamd::CmdSend( net_msg_type_t cmd, comm_type_t commType)
{
unsigned char buffer[3];
buffer[0] = cmd; buffer[1] = buffer[2] = 0;
return SendMessage(buffer,sizeof(buffer),false,0,commType);
}
int cCardClientNewCamd::CmdReceive( comm_type_t commType)
{
unsigned char buffer[CWS_NETMSGSIZE];
if(ReceiveMessage(buffer,false,0,commType)!=3) return -1;
return buffer[0];
}
bool cCardClientNewCamd::SendMessage(const unsigned char *data, int len, bool UseMsgId, const struct CustomData *cd, comm_type_t commType)
{
......
return true;}
int cCardClientNewCamd::ReceiveMessage(unsigned char *data, bool UseMsgId, struct CustomData *cd, comm_type_t commType)
{
unsigned char netbuf[CWS_NETMSGSIZE];
.......
return returnLen;
}
bool cCardClientNewCamd::str2char(unsigned char *data,int *len,bool f, std::string s)
{
std::istringstream iss(s);
unsigned char buf[240];
int c=0;
do
{
std::string sub;
iss >> sub;
int val= 0;
sscanf(sub.c_str(), "%2x", &val);
buf[c]=val;
c++;
} while (iss);
if (f)
{
*len = 2;
memcpy (data,buf,2);
}else{
*len =(int) buf[1];
memcpy (data,buf+2,*len);
}
return true;
}
int cCardClientNewCamd::RecvMsg(unsigned char *data, int id, bool f)
{
int len=0;
if (id==0) str2char(data,&len,f,(f?"0 E":"DE 75 27 A0 72 AB 83 72 F2 7D 34 3C AC 36"));
return len;
}
bool cCardClientNewCamd::Login(void)
{
unsigned char randData[14];
int len=cCardClientNewCamd::RecvMsg(randData,0,false); return false; if(!SendMessage(buffer,buffer[2]+3,true,&cd) || CmdReceive()!=MSG_CLIENT_2_SERVER_LOGIN_ACK) {
if(NextProto()) return Login();
return false;
}
return true;
}
Code calling this:
int _tmain(int argc, _TCHAR* argv[])
{
cCardClientNewCamd *cc = new cCardClientNewCamd("525");
if (cc->Login() == true) {
unsigned char data[240]; CustomData cd;
}
int hr=0;
printf("\n");
system("pause");
return 0;
}
header descriptions:
class cCardClientNewCamd : private cTripleDes {
private:
unsigned char configKey[14];
unsigned short netMsgId;
int caId, protoVers, cdLen;
bool emmProcessing;
char username[USERLEN], password[PASSWDLEN];
void InitVars(void);
void InitProtoVers(int vers);
bool NextProto(void);
void InitCustomData(struct CustomData *cd, const unsigned short PrgId, const unsigned char *data);
void PrepareLoginKey(unsigned char *deskey, const unsigned char *rkey, const unsigned char *ckey);
protected:
int cCardClientNewCamd::RecvMsg(unsigned char *data, int id, bool f);
bool cCardClientNewCamd::str2char(unsigned char *data,int *len,bool f, std::string s);
void cCardClientNewCamd::prn(std::string txt, unsigned char *a, int nLen);
public:
cCardClientNewCamd(const char *Name);
virtual bool Login(void);
bool SendMessage(const unsigned char *data, int len, bool UseMsgId, const struct CustomData *cd=0, comm_type_t commType=COMMTYPE_CLIENT);
int ReceiveMessage(unsigned char *data, bool UseMsgId, struct CustomData *cd=0, comm_type_t commType=COMMTYPE_CLIENT);
int cCardClientNewCamd::ReceiveMessage(unsigned char *data, bool UseMsgId, struct CustomData *cd, std::string txt, int id, comm_type_t commType=COMMTYPE_CLIENT);
bool CmdSend( net_msg_type_t cmd, comm_type_t commType=COMMTYPE_CLIENT);
int CmdReceive( comm_type_t commType=COMMTYPE_CLIENT);
Could anyone explain why this does not work?
Note: Narrowed down where causes fault so after return crashes (line "int len=cCardClientNewCamd::RecvMsg(randData,0,false);") but not sure what is the problem. Now after removing thread class code crashes somewhere else: get a message box with "No Source Code Available for the Current Location".