|
ID: 19378, DLLs and shared variables
How do set it up to make variables in the DLL initialized once, then shared among the apps that use the exported functions?
|
Download
| Details
|
|
FTP
download also available
|
0 bytes |
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
|
To download this, you must have registered:
|
For C++Builder, Version 5.5
to 5.5
5 downloads
Copyright: No significant restrictions
Size: 0 bytes
Updated on Thu, 19 Dec 2002 11:26:19 GMT
Originally uploaded on Thu, 19 Dec 2002 11:20:01 GMT
|
|
Description
|
Hi!
I'm using the Borland C++ 5.5.1 Compiler and Command Line Tools, and I'm trying to build a DLL. What I want is for a global variable to be initialized globally, instead of per instance, and shared among any apps that use any of the exported functions.
I have tried various settings, but without success.
Any ideas?
// mydll.h
#include
#include
typedef std::vector::size_type vecSize
// this one I want to be shared (i.e. initialized globally)
std::vector myStrings;
extern "C" __declspec(dllexport) vecSize getSize();
extern "C" __declspec(dllexport) std::string getString(vecSize index);
extern "C" __declspec(dllexport) void addString(std::string str);
// mydll.cpp
#include
#include "mydll.h"
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
return TRUE;
}
vecSize getSize()
{
return myStrings.size();
}
std::string getString(vecSize index)
{
return myStrings[index];
}
void addString(std::string str)
{
myStrings.push_back(str);
}
// mydll.def
LIBRARY mydll INITGLOBAL
DESCRIPTION 'My DLL'
CODE PRELOAD FIXED EXECUTEREAD NONDISCARDABLE
DATA PRELOAD FIXED READWRITE SINGLE SHARED
HEAPSIZE 4096
STACKSIZE 1048576
EXPORTS
getSize=_getSize @1 RESIDENTNAME
getString=_getString @2 RESIDENTNAME
addString=_addString @3 RESIDENTNAME
And here's how I built it:
bcc32.exe -c -tWD mydll.cpp
ilink32.exe -Tpd -aa c0d32.obj mydll.obj,mydll.dll,mydll.map,import32.lib cw32.lib,mydll.def,
|
|

Server Response from: ETNACDC04
|
Connect with Us