Click here to Skip to main content
15,886,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello C/C++ Guru:



I have a small questions in the behavior of Structure, I have declare a structure with 10 components. Some of the components in the structure has already their value but when I use

the structure components in a function DLL function those value I set previously has been deleted or empty. I don't know what is the problem... can someone else out there help me



Regards,
Byze
Posted
Comments
Mohibur Rashid 31-Oct-13 4:09am    
let us see the code
Fredrik Bornander 31-Oct-13 4:10am    
We need to see how your using or passing the initialized struct.
kpax1684 31-Oct-13 5:25am    
Here is my code..,

<pre lang="cs">typedef struct s_StudentPro
{
char Prog1[15];
char Prog2[15];
char Student1[15];
char Student1[15];
} s_STUDENTPRO;</pre>


short __stdcall DLLEXPORT CheckStudP(char STD[50], void *Mom)
{

<pre lang="cs">s_STUDENTPRO*sTudent;
sTudent= mom;
sTudent= calloc(1,sizeof(struct sTudent));</pre>

sprintf(sTudent->Prog1,"SuperCompT");
sprintf(sTudent->Prog2,"SuperCompT");

std_GetInfo(sTudent->Prog1, sTudent->cbOrderVersion, sTudent->Student1, sTudent->Student1, &dllStp);
Richard MacCutchan 31-Oct-13 6:31am    
You have two fields with the same name (Student1), and a field name that does not exist (sTudent->cbOrderVersion) so this will not even compile. Try using copy and paste to paste your exact code into your original question, using the Improve question link.
Aescleal 31-Oct-13 4:23am    
What the previous commentators said plus are you using C or C++?

your structure has some memory which can have random values. (That behavior isnt defined in C!!!). So you better initialize all components with proper values of your struct.

Consider using a class with its components, so you can deploy a useful constructor, destructor and some functionality.
 
Share this answer
 
Answer these questions then see what happens:

- Why are you assigning a void pointer to your local pointer then immediately writing over it?

- why have you two structure members with the same name?

- why are you accessing a member of the structure (cbOrderVersion) that doesn't exist in the structure definition?

I'm surprised that lot even compiles TBH.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900