| View previous topic :: View next topic |
| Author |
Message |
KingOrmon Guest
|
Posted: Fri Jun 17, 2005 11:00 am Post subject: How could I put a global variable in a dll ? |
|
|
Hello,
I need to declare a global var inside dll:
namespace ZQuery
{
static AnsiString sSGBD = "";
extern "C" void _stdcall zDLLInit(char * szSGDB)
{
sSGBD = AnsiString(szSGDB);
}
}
in app call:
ZQuery::zDLLInit("ORACLE");
It compile but the global var sSGBD is blank !!!
regards
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri Jun 17, 2005 11:03 am Post subject: Re: How could I put a global variable in a dll ? |
|
|
KingOrmon wrote:
| Quote: | I need to declare a global var inside dll:
namespace ZQuery
{
static AnsiString sSGBD = "";
|
If you put that in a namespace then in my opinion
it is not global. For global just place
AnsiString sSGBD;
in your DLL codefile.
| Quote: | It compile but the global var sSGBD is blank !!!
|
Where is it blank ? In the App or in the DLL ?
You did not show the code how you checked that.
Please do.
Is this a 'writingcomponents' problem ?
Hans.
|
|
| Back to top |
|
 |
KingOrmon Guest
|
Posted: Fri Jun 17, 2005 11:48 am Post subject: Re: How could I put a global variable in a dll ? |
|
|
sSGBD is blank in the DLL;
when i call zDLLInit("ORACLE");
the text "ORACLE" is not copied to the var
even when I dont use namespaces
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri Jun 17, 2005 11:49 am Post subject: Re: How could I put a global variable in a dll ? |
|
|
KingOrmon wrote:
| Quote: | sSGBD is blank in the DLL;
when i call zDLLInit("ORACLE");
|
Why did you change that ?
ZQuery::zDLLInit("ORACLE");
was ok.
| Quote: | the text "ORACLE" is not copied to the var
even when I dont use namespaces
|
You still did not show the code that did the check.
Nor where you placed that code. You can keep your namespace
but put a global var out of it.
Hans.
|
|
| Back to top |
|
 |
KingOrmon Guest
|
Posted: Fri Jun 17, 2005 12:06 pm Post subject: Re: How could I put a global variable in a dll ? |
|
|
DLL CODE:
#ifndef DLLMODE
#ifdef __ZGESTIONAPP__
#define DLLMODE extern "C" __declspec(dllimport)
#else
#define DLLMODE extern "C" __declspec(dllexport)
#endif
#define CALLTYPE _stdcall
#endif
static AnsiString sSGBD = "";
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
DLLMODE void CALLTYPE zDLLInit(char * szSGDB)
{
sSGBD = AnsiString(szSGDB); // Assing value example "HELLO WORLD"
}
DLLMODE void CALLTYPE ShowValue()
{
ShowMessage(sSGBD ); // The value is always blank !!!
}
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri Jun 17, 2005 12:38 pm Post subject: Re: How could I put a global variable in a dll ? |
|
|
KingOrmon wrote:
| Quote: | static AnsiString sSGBD = "";
|
Change that to:
AnsiString sSGBD = "HERE I AM";
Now what does ShowValue show before and after a call to
zDLLInit ?
You could also check inside zDLLInit:
| Quote: | DLLMODE void CALLTYPE zDLLInit(char * szSGDB)
{
Showmessage ( sSGBD ); |
| Quote: | sSGBD = AnsiString(szSGDB); // Assing value example "HELLO WORLD"
|
Showmessage ( sSGBD );
Please report what you see in the different cases.
Until now all your code is for a variable global to the DLL.
Not to the application that uses the DLL.
Hans.
|
|
| Back to top |
|
 |
KingOrmon Guest
|
Posted: Fri Jun 17, 2005 12:53 pm Post subject: Re: How could I put a global variable in a dll ? |
|
|
The showed text is always "HERE I AM"
but inside of dll the var is assigned by the
the project is working:
if ( sSGBD == "ORACLE" )
ShowMessage("ORA");
else
if ( sSGBD == "MSSQL" )
ShowMessage("SQL");
why ?
"Hans Galema" <notused (AT) notused (DOT) nl> escribió en el mensaje
news:42b2c519 (AT) newsgroups (DOT) borland.com...
| Quote: | KingOrmon wrote:
static AnsiString sSGBD = "";
Change that to:
AnsiString sSGBD = "HERE I AM";
Now what does ShowValue show before and after a call to
zDLLInit ?
You could also check inside zDLLInit:
DLLMODE void CALLTYPE zDLLInit(char * szSGDB)
{
Showmessage ( sSGBD );
sSGBD = AnsiString(szSGDB); // Assing value example "HELLO WORLD"
Showmessage ( sSGBD );
}
Please report what you see in the different cases.
Until now all your code is for a variable global to the DLL.
Not to the application that uses the DLL.
Hans.
|
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri Jun 17, 2005 12:54 pm Post subject: Re: How could I put a global variable in a dll ? |
|
|
KingOrmon wrote:
| Quote: | The showed text is always "HERE I AM"
but inside of dll the var is assigned by the
the project is working:
if ( sSGBD == "ORACLE" )
ShowMessage("ORA");
else
if ( sSGBD == "MSSQL" )
ShowMessage("SQL");
|
Why not just one ShowMessage ( sSGBD ) ?
Please just answer my questions beacause this confuses me.
As you repost my whole post you could just use it to tell what
you see where.
| Quote: | You could also check inside zDLLInit:
DLLMODE void CALLTYPE zDLLInit(char * szSGDB)
{
Showmessage ( sSGBD );
|
Now what did you see here ?
| Quote: |
sSGBD = AnsiString(szSGDB); // Assing value example "HELLO WORLD"
Showmessage ( sSGBD );
|
And what did you see here ?
Hans.
|
|
| Back to top |
|
 |
KingOrmon Guest
|
Posted: Fri Jun 17, 2005 1:09 pm Post subject: Re: How could I put a global variable in a dll ? |
|
|
| Quote: | AnsiString sSGBD = "HERE I AM";
You could also check inside zDLLInit:
DLLMODE void CALLTYPE zDLLInit(char * szSGDB)
{
Showmessage ( sSGBD );
|
Show text "HERE I AM";
| Quote: |
sSGBD = AnsiString(szSGDB); // Assing value example "HELLO WORLD"
Showmessage ( sSGBD );
|
Show text "ORACLE"; // the value of szSGDB
If I call ShowValue AFTER invoke zDLLInit
the showed text is "HERE I AM";
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri Jun 17, 2005 2:19 pm Post subject: Re: How could I put a global variable in a dll ? |
|
|
KingOrmon wrote:
| Quote: | If I call ShowValue AFTER invoke zDLLInit
the showed text is "HERE I AM";
|
Well I'm baffled as that should not happen.
The only thing that I can think of is that you violate against how to
handle global variables and that there are more instances of sSGDB.
But then the linker should warn you for that. Does it ?
Be sure that
AnsiString sSGBD = "HERE I AM";
is in one .cpp file only. You cannot put that in a .h file.
Now if you want to use sSGBD in the same .cpp file then all is
ok already.
If however you want to use sSGDB also in another .cpp file than
before using sSGDB you have to write a line:
extern AnsiString sSGDB;
and after that for instance
ShowMessage ( sSGDB );
What I suspect is that you have AnsiString sSGBD = "HERE I AM";
in a .h file. You will have as many instances of sSGDB as the number
of .cpp files that include that .h file.
Hans.
|
|
| Back to top |
|
 |
|