From: karim on
Hi All,
i have the following code in my cpp file
**************************************************
int i = 0;

char *passwordToEncrypt = "080000151F6ECF67";
char *encpwd8 = NULL;
char *encpwd16 = NULL;

//if i uncomment below line,then it throwing access violation error during
runtime
//i = 0605;

int l = E3Des(passwordToEncrypt, encpwd8, encpwd16, &i);

****************************************************

the method "E3Des" is defined in a dll and it is linked. so no compilation
errors:-). i have only runtime error.

can anybody help me out.

Thanks,
karimulla.


From: David Wilkinson on
karim wrote:
> Hi All,
> i have the following code in my cpp file
> **************************************************
> int i = 0;
>
> char *passwordToEncrypt = "080000151F6ECF67";
> char *encpwd8 = NULL;
> char *encpwd16 = NULL;
>
> //if i uncomment below line,then it throwing access violation error during
> runtime
> //i = 0605;
>
> int l = E3Des(passwordToEncrypt, encpwd8, encpwd16, &i);
>
> ****************************************************
>
> the method "E3Des" is defined in a dll and it is linked. so no compilation
> errors:-). i have only runtime error.
>
> can anybody help me out.

karimulla:

What is the declaration of E3Des()? Does it modify the first parameter?
It would seem that it does. In that case you must pass it a modifiable
character string

char passwordToEncrypt[1024] = "080000151F6ECF67";

(assuming that 1024 is long enough).

Additional point: when you assign a string literal to a char pointer you
should always write

const char *passwordToEncrypt = "080000151F6ECF67";

Then the compiler will stop you from passing it to a function that will
modify the string (i.e. one that takes char* as argument).

--
David Wilkinson
Visual C++ MVP
From: karim on
hi David,

"David Wilkinson" wrote:

> karim wrote:
> > Hi All,
> > i have the following code in my cpp file
> > **************************************************
> > int i = 0;
> >
> > char *passwordToEncrypt = "080000151F6ECF67";
> > char *encpwd8 = NULL;
> > char *encpwd16 = NULL;
> >
> > //if i uncomment below line,then it throwing access violation error during
> > runtime
> > //i = 0605;
> >
> > int l = E3Des(passwordToEncrypt, encpwd8, encpwd16, &i);
> >
> > ****************************************************
> >
> > the method "E3Des" is defined in a dll and it is linked. so no compilation
> > errors:-). i have only runtime error.
> >
> > can anybody help me out.
>
> karimulla:
>
> What is the declaration of E3Des()? Does it modify the first parameter?
see the declaration below
int E3Des(char *Passwd_en_Claro, char *Passwd_Encriptado8, char*
Passwd_Encriptado16, int *version);
and it doesn't modify the first parameter.
> It would seem that it does. In that case you must pass it a modifiable
> character string
>
> char passwordToEncrypt[1024] = "080000151F6ECF67";
>
> (assuming that 1024 is long enough).
>
> Additional point: when you assign a string literal to a char pointer you
> should always write
>
> const char *passwordToEncrypt = "080000151F6ECF67";
i don't have any problem with above parameter. i got error when i pass +ve
value to "i" variable.
> Then the compiler will stop you from passing it to a function that will
> modify the string (i.e. one that takes char* as argument).
>
> --
> David Wilkinson
> Visual C++ MVP
>
-karimulla.
From: kalpesh on
On Jul 6, 5:38 pm, karim <k...(a)discussions.microsoft.com> wrote:
> hi David,
>
>
>
>
>
> "David Wilkinson" wrote:
> > karim wrote:
> > > Hi All,
> > > i have the following code in my cpp file
> > > **************************************************
> > > int i = 0;
>
> > > char *passwordToEncrypt = "080000151F6ECF67";
> > > char *encpwd8 = NULL;
> > > char *encpwd16 = NULL;
>
> > > //if i uncomment below line,then it throwing access violation error during
> > > runtime
> > > //i = 0605;
>
> > > int l = E3Des(passwordToEncrypt, encpwd8, encpwd16, &i);
>
> > > ****************************************************
>
> > > the method "E3Des" is defined in a dll and it is linked. so no compilation
> > > errors:-). i have only runtime error.
>
> > > can anybody help me out.
>
> > karimulla:
>
> > What is the declaration of E3Des()? Does it modify the first parameter?
>
> see the declaration below
> int E3Des(char *Passwd_en_Claro, char *Passwd_Encriptado8, char*
> Passwd_Encriptado16, int *version);
> and it doesn't modify the first parameter.> It would seem that it does. In that case you must pass it a modifiable
> > character string
>
> > char passwordToEncrypt[1024] = "080000151F6ECF67";
>
> > (assuming that 1024 is long enough).
>
> > Additional point: when you assign a string literal to a char pointer you
> > should always write
>
> > const char *passwordToEncrypt = "080000151F6ECF67";
>
> i don't have any problem with above parameter. i got error when i pass +ve
> value to "i" variable.> Then the compiler will stop you from passing it to a function that will
> > modify the string (i.e. one that takes char* as argument).
>
> > --
> > David Wilkinson
> > Visual C++ MVP
>
> -karimulla.- Hide quoted text -
>
> - Show quoted text -

i think the problem create using the second and third parametet (char
*encpwd8 = NULL; char *encpwd16 = NULL;) which you pass as char *
without initialize its memory so when ever you are trying to copy some
string in this two parameter inside your E3Des function it will thow
memory exception and your application will crash.
so use all pointer variable with proper memory initialization.


From: David Wilkinson on
karim wrote:

>> What is the declaration of E3Des()? Does it modify the first parameter?
> see the declaration below

> int E3Des(char *Passwd_en_Claro, char *Passwd_Encriptado8, char*
> Passwd_Encriptado16, int *version);

> and it doesn't modify the first parameter.

In that case I would think that you must pass real strings (of
sufficient length) as the second and third parameters. You really have
to look at the documentation to see what it expects.

If the function does not modify the first parameter then it "should" be
declared as

int E3Des(const char *Passwd_en_Claro, char *Passwd_Encriptado8, char*
Passwd_Encriptado16, int *version);

to indicate that is safe to pass a string literal.

--
David Wilkinson
Visual C++ MVP
 |  Next  |  Last
Pages: 1 2 3 4
Prev: CHtmlView
Next: using MXXMLWriter to pretty print xml