How to return a structure variable from a function ?
-
Hello all, I am a newbie. I want to know how can I return a structure variable from a function to the calling function. I have a structure named httpsData which contains following fields: typedef struct { char httpServerName[25]; char httpReqHeaders[255]; char httpVerb[5]; char httpRetHeaders[255]; char httpRetMessage[2048]; }httpsData; I want to return a variable of type httpsdata. Can I use httpsData as function return type ? Thanks for your prompt answer. Nikhs Nikhil Trivedi
-
Hello all, I am a newbie. I want to know how can I return a structure variable from a function to the calling function. I have a structure named httpsData which contains following fields: typedef struct { char httpServerName[25]; char httpReqHeaders[255]; char httpVerb[5]; char httpRetHeaders[255]; char httpRetMessage[2048]; }httpsData; I want to return a variable of type httpsdata. Can I use httpsData as function return type ? Thanks for your prompt answer. Nikhs Nikhil Trivedi
Nikhil Trivedi wrote:
Can I use httpsData as function return type
Sure you can use.
struct httpsData _MyFunction(Param1,...)
will do, but this is returing the struct as value type
Do your Duty and Don't expect the Result
-
Hello all, I am a newbie. I want to know how can I return a structure variable from a function to the calling function. I have a structure named httpsData which contains following fields: typedef struct { char httpServerName[25]; char httpReqHeaders[255]; char httpVerb[5]; char httpRetHeaders[255]; char httpRetMessage[2048]; }httpsData; I want to return a variable of type httpsdata. Can I use httpsData as function return type ? Thanks for your prompt answer. Nikhs Nikhil Trivedi
Nikhil Trivedi wrote:
I want to return a variable of type httpsdata. Can I use httpsData as function return type ?
Pass httpsdata as a reference... this helps you to return an execution status value too, which won't be possible if you are returning a structure.
int GetHTTPSData( httpsdata& httpsData_o )
{
httpsData_o = anotherHttpsData;
return 0; // All went well
}
Nibu thomas A Developer Programming tips[^] My site[^]
-
Nikhil Trivedi wrote:
I want to return a variable of type httpsdata. Can I use httpsData as function return type ?
Pass httpsdata as a reference... this helps you to return an execution status value too, which won't be possible if you are returning a structure.
int GetHTTPSData( httpsdata& httpsData_o )
{
httpsData_o = anotherHttpsData;
return 0; // All went well
}
Nibu thomas A Developer Programming tips[^] My site[^]
Nibu babu thomas wrote:
Pass httpsdata as a reference... this helps you return a execution status value too, which won't be possible
After execution of the function, Can I access the elements which are modified during the function execution. If so how ? Thanks for your reply. Nikhs Nikhil Trivedi
-
Nibu babu thomas wrote:
Pass httpsdata as a reference... this helps you return a execution status value too, which won't be possible
After execution of the function, Can I access the elements which are modified during the function execution. If so how ? Thanks for your reply. Nikhs Nikhil Trivedi
Like this,
struct __dummy {
int i;
int j;
}Dummy;bool LoadValues(struct Dummy**&** src)
{
src.i = 1;
src.j = 2;return true/false; /* Depends, assume here true */
}void SumFns(..)
{
struct Dummy MyDummyValue = {0};
if (LoadValues(MyDummyValue))
{
/* Succeeded */
/* Now if you access 'MyDummyValue', you can have the data */
int a = MyDummyValue.i; /* a will be assigned as 1 */
int b = MyDummyValue.j; /* b will be assigned as 2 */
}
else
/* Failed */
}
Do your Duty and Don't expect the Result
-
Like this,
struct __dummy {
int i;
int j;
}Dummy;bool LoadValues(struct Dummy**&** src)
{
src.i = 1;
src.j = 2;return true/false; /* Depends, assume here true */
}void SumFns(..)
{
struct Dummy MyDummyValue = {0};
if (LoadValues(MyDummyValue))
{
/* Succeeded */
/* Now if you access 'MyDummyValue', you can have the data */
int a = MyDummyValue.i; /* a will be assigned as 1 */
int b = MyDummyValue.j; /* b will be assigned as 2 */
}
else
/* Failed */
}
Do your Duty and Don't expect the Result
Thanks to both of you, friends. This really helped me a lot. Thanks again Nikhs Nikhil Trivedi
-
Hello all, I am a newbie. I want to know how can I return a structure variable from a function to the calling function. I have a structure named httpsData which contains following fields: typedef struct { char httpServerName[25]; char httpReqHeaders[255]; char httpVerb[5]; char httpRetHeaders[255]; char httpRetMessage[2048]; }httpsData; I want to return a variable of type httpsdata. Can I use httpsData as function return type ? Thanks for your prompt answer. Nikhs Nikhil Trivedi
the short answer: yes the long answer: have u tried it ? The process of learning coding requires a lot of trial and error. You should have tried it to see if it works before asking such question.
-
Hello all, I am a newbie. I want to know how can I return a structure variable from a function to the calling function. I have a structure named httpsData which contains following fields: typedef struct { char httpServerName[25]; char httpReqHeaders[255]; char httpVerb[5]; char httpRetHeaders[255]; char httpRetMessage[2048]; }httpsData; I want to return a variable of type httpsdata. Can I use httpsData as function return type ? Thanks for your prompt answer. Nikhs Nikhil Trivedi
Is this the same problem as your question from yesterday[^] ? If yes, from where do you want to use this dll ? If it is not from a C++ program, then you'll need to pay extra consideration about converting the strings. For example if you use it in VB, the conversion is not trivial (as far as I remember).
Cédric Moonen Software developer
Charting control [v1.2 - Updated] -
Is this the same problem as your question from yesterday[^] ? If yes, from where do you want to use this dll ? If it is not from a C++ program, then you'll need to pay extra consideration about converting the strings. For example if you use it in VB, the conversion is not trivial (as far as I remember).
Cédric Moonen Software developer
Charting control [v1.2 - Updated]Cedric Moonen wrote:
Is this the same problem as your question from yesterday[^] ?
Yes. It is the same problem. I want to modify my DLL and i would be using this DLL out of the C++ environment. This environment is also built up in C++. So I think It should work. I am trying to do so. Hope it would work. Thanks for your concern. Nikhs Nikhil Trivedi
-
Like this,
struct __dummy {
int i;
int j;
}Dummy;bool LoadValues(struct Dummy**&** src)
{
src.i = 1;
src.j = 2;return true/false; /* Depends, assume here true */
}void SumFns(..)
{
struct Dummy MyDummyValue = {0};
if (LoadValues(MyDummyValue))
{
/* Succeeded */
/* Now if you access 'MyDummyValue', you can have the data */
int a = MyDummyValue.i; /* a will be assigned as 1 */
int b = MyDummyValue.j; /* b will be assigned as 2 */
}
else
/* Failed */
}
Do your Duty and Don't expect the Result
Hello dear friend, I am successful in calling the function with passing values as reference but when I access the values in calling application which is out side of the c++ environement, I am getting those as NULL. Can you tell me the reason. Nikhs Nikhil Trivedi