Ramesh
2010-05-18 21:26:13 UTC
Hello I used module definition file to export a variable(a special
struct variable). I then tried to access it in my code, I can access
it. But the problem is, I change that external variable inside a
function. But even after changing it, it has the same value. The
following demonstration code might explain
----------------------------------------------------------------------------------------------------
//some.h
typedef struct{
double i;
double r;
}dcomplex;
dcomplex add(dcomplex a,dcomplex b);
dcomplex subtract(dcomplex a, dcomplex b);
extern dcomplex IValue;
----------------------------------------------------------------------------------------------------
//some.c #these are the exported functions
#include "some.h"
dcomplex IValue ; // this is defined as extern
dcomplex add(dcomplex a, dcomplex b){
dcomplex c;
IValue.i = 1.0;
IValue.r = 0.0;
c.i = a.i + b.i;
c.r = a.r + b.r;
return c;
}
dcomplex subtract(dcomplex a, dcomplex b){
dcomplex c;
IValue.i = 2;
IValue.r = 0.0;
c.i = a.i + b.i;
c.r = a.r + b.r;
return c;
}
---------------------------------------------------------------------------
//some.def
LIBRARY "ExportThisExperiment2"
EXPORTS
add
subtract
IValue
---------------------------------------------------------------------------------------------------------------------
// A different project using the dll generated by the other
// main.c
#include "some.h"
#include <stdio.h>
int main(){
dcomplex i,j,k;
i.i=23.52;
i.r = -12.5;
j.r = 2.356;
j.i = -22.52;
printf("i Value = (%lf + %lfi)\n",IValue.r,IValue.i);
k = add(i,j);
printf("(%lf + %lfi)+(%lf + %lfi)=(%lf + %lfi)
\n",i.r,i.i,j.r,j.i,k.r,k.i);
printf("i Value = (%lf + %lfi)\n",IValue.r,IValue.i);
k = subtract(i,j);
printf("(%lf + %lfi)-(%lf + %lfi)=(%lf + %lfi)
\n",i.r,i.i,j.r,j.i,k.r,k.i);
printf("i Value = (%lf + %lfi)\n",IValue.r,IValue.i);
return 0;
}
---------------------------------------------------------------------------
Even this simple demonstration code doesn't work. It compiles and
executes. But it is never initialized or changed. It is some junk
value always even after calling add and subtract. Any help would be
appreciated.
ramesh
struct variable). I then tried to access it in my code, I can access
it. But the problem is, I change that external variable inside a
function. But even after changing it, it has the same value. The
following demonstration code might explain
----------------------------------------------------------------------------------------------------
//some.h
typedef struct{
double i;
double r;
}dcomplex;
dcomplex add(dcomplex a,dcomplex b);
dcomplex subtract(dcomplex a, dcomplex b);
extern dcomplex IValue;
----------------------------------------------------------------------------------------------------
//some.c #these are the exported functions
#include "some.h"
dcomplex IValue ; // this is defined as extern
dcomplex add(dcomplex a, dcomplex b){
dcomplex c;
IValue.i = 1.0;
IValue.r = 0.0;
c.i = a.i + b.i;
c.r = a.r + b.r;
return c;
}
dcomplex subtract(dcomplex a, dcomplex b){
dcomplex c;
IValue.i = 2;
IValue.r = 0.0;
c.i = a.i + b.i;
c.r = a.r + b.r;
return c;
}
---------------------------------------------------------------------------
//some.def
LIBRARY "ExportThisExperiment2"
EXPORTS
add
subtract
IValue
---------------------------------------------------------------------------------------------------------------------
// A different project using the dll generated by the other
// main.c
#include "some.h"
#include <stdio.h>
int main(){
dcomplex i,j,k;
i.i=23.52;
i.r = -12.5;
j.r = 2.356;
j.i = -22.52;
printf("i Value = (%lf + %lfi)\n",IValue.r,IValue.i);
k = add(i,j);
printf("(%lf + %lfi)+(%lf + %lfi)=(%lf + %lfi)
\n",i.r,i.i,j.r,j.i,k.r,k.i);
printf("i Value = (%lf + %lfi)\n",IValue.r,IValue.i);
k = subtract(i,j);
printf("(%lf + %lfi)-(%lf + %lfi)=(%lf + %lfi)
\n",i.r,i.i,j.r,j.i,k.r,k.i);
printf("i Value = (%lf + %lfi)\n",IValue.r,IValue.i);
return 0;
}
---------------------------------------------------------------------------
Even this simple demonstration code doesn't work. It compiles and
executes. But it is never initialized or changed. It is some junk
value always even after calling add and subtract. Any help would be
appreciated.
ramesh