Re: Using TLSAlloc to read data into a DLL
"Sanjay" <sanjay.gangadhara@gmail.com> wrote in message
news:8a7226de-9dc6-4c77-b260-7de682c775db@d21g2000prf.googlegroups.com
How would I go about defining a global variable for this simple
example? (I want "x" to be the global variable):
#define MAX_LENGTH 100
BOOL WINAPI DllMain (HANDLE hInst, ULONG ul_reason_for_call, LPVOID
lpReserved)
{
static double *x=NULL;
FILE *in;
char out[MAX_LENGTH];
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
x = malloc(MAX_LENGTH);
in = fopen("Test.txt", "rt")
fgets(out, MAX_LENGTH, in);
x = strtod(out,NULL);
close (in);
This code doesn't compile, and doesn't make much sense to me. It's not
clear what you are trying to do here.
If all you need is to read one double value from the file and store it
globally, just declare a double variable outside of any function:
double MyValue;
This is how one declares a global variable. Any function can just refer
to it by name.
int __declspec(dllexport) APIENTRY Test(Data *y)
{
static double *x, *y;
y = x*x
return 0;
}
This code makes even less sense. For one thing, don't you have too many
variables named 'y' ?
With all due respect, maybe you need to spend some time with your
favorite C or C++ textbook.
I do not think that I should be
using STATIC variable types, because this doesn't seem to work.
Not at all surprising. Do you know what 'static' keyword is for? You
seem to believe it's magic fairie dust you can sprinkle over random
parts of code to make it work better. Programming doesn't normally work
this way - you are supposed to know what you are doing.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925