Public Group

# Static data/functions in a dll

This topic is 4572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was writing a dll that has something like this in it...

static SystemRecord SystemLocalHost;

SystemRecord * GetSystemRecord( )
{
return &SystemLocalHost;
}


This is inside a C file and GetSystemRecord is defined in it's header. Normally I dont' use globals but it's impossible to avoid in this instance, so I encapsulated it around a function and kept it local to the C file. I thought that was good practice. However, this function will always return NULL, and as you can see for yourself, it clearly should not. This code is inside a Windows dll compiled with MinGW 3.4 and executed from a program linked to it using the same compiler. It may be helpful to note that the same error presists whether SystemLocalHost is static or not, and regardless whether I make GetSystemRecord __stdcall or not. Also, the program does not call this function directly, but it's called by proxy (through an other function) and I determined the error by using MessageBox on the the return value of this.

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5
gaxio
12

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631724
• Total Posts
3001897
×