Functions exported in C++ and global variables;

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Functions exported in C++ and global variables;

Hello,

I'm working with a DLL project in VISUAL C++ that exports one function with
the sentence
__declspec(dllexport). The problem is that this function returns the value
of a dll global
variable, but in fact the application that imports this functions from the
dll only see the
initial value of the global variable of the dll, but it doesn't remark
changes of value in this global
variable.

// This is an example of an exported function.
IMPORTINGDLL_API int fnProvadll(void)
{
return xavi;
}

//and the global variable in the DLL is defined like this:

int xavi=0;

What could be the problem? Please some advice from you will be useful!
Thanks all people!

Sincerely,

javitobcn
 
xbsantos said:
Functions exported in C++ and global variables;

Hello,

I'm working with a DLL project in VISUAL C++ that exports one function with
the sentence
__declspec(dllexport). The problem is that this function returns the value
of a dll global
variable, but in fact the application that imports this functions from the
dll only see the
initial value of the global variable of the dll, but it doesn't remark
changes of value in this global
variable.

// This is an example of an exported function.
IMPORTINGDLL_API int fnProvadll(void)
{
return xavi;
}

//and the global variable in the DLL is defined like this:

int xavi=0;

What could be the problem? Please some advice from you will be useful!
Thanks all people!

Sincerely,

javitobcn


Where is the global variable being set. I tried setting it in the fnProvadll
function definition and dont get into this issue.


//1.cpp

int xavi = 0;

__declspec(dllexport) int fnProvadll(void)
{
xavi = 9;
return xavi;
}

//m.cpp

using namespace System;
#include <stdio.h>
__declspec(dllimport) int fnProvadll(void);

int main()
{
printf("Val is %d\n",fnProvadll());
}

cl /LD /EHsc 1.cpp
cl /clr m.cpp /link 1.lib
m.exe


I do get the correct value of global here. Can you post more code for us to
figure out what is happening here.

Thanks,
Kapil
 
Back
Top