共享库和应用程序之间传输数据 [英] transfer the data between shared library and application

查看:119
本文介绍了共享库和应用程序之间传输数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有共同的图书馆,在那里我做了一些数据代/处理,我已经写了一些API和应用程序来访问他们,并进行数据传输。

I have shared library where I does some data generations/processing , and I have written some APIs and application to access them and transfer the data .

/**************APPLICATION*********/

/**************APPLICATION*********/

 char* data1;

 char* data2;

 genratedCamData(1, char* data1 , char *data2);

 printf(" data1 %s ",data1);
 printf(" data2 %s ",data2);
 free(data2);

/ * 的**的 * 的**的 * 的**的 * 的** 库内的 的**的 * 的**的 * 的**的 * 的**的 * 的**的 * 的* /

/************Inside Library ****************/

 int genratedCamData(1, char* datafirst , char *datasecond)

 {

 if(CAM==1)
 datafirst=getCam1data();

 printf(" test at lib %s ",type);

 datasecond=malloc(sizeof(char) * 100);
 sprintf(datafirst,"%s",datasecond);

 return 0;

 }

我试过上面的方法获取数据到应用程序,但数据正确打印库中,但出方的lib(应用程序),它没有打印任何内...

I tried above method get the data to application , but data prints properly inside the library but out side the lib (in the application ) it does not print anything ...

一些身体可以帮助我用最好的方式来进行数据通信的B / W库和应用程序。

Can some body help me to use a best way to communicate the data b/w libs and application .

推荐答案

由于下用价值,包括指针传递参数,你需要通过的地址指针焦炭** ,一个函数,使函数指针指向不同的地址,并有给调用者可见的那些变化:

As C passes arguments by value, including pointers, you need to pass the address of the pointers, char**, to a function to enable the function to point the pointers to a different address and have those changes visible to the caller:

int genratedCamData(int CAM, char** datafirst , char **datasecond)
{
    *datafirst=getCam1data();
    *datasecond=malloc(100); /* sizeof(char) is guaranteed to be 1. */
}

调用:

char* data1;
char* data2;
genratedCamData(1, &data1 , &data2);

这篇关于共享库和应用程序之间传输数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆