NO

Author Topic: Some help with pragma data_seg()  (Read 6499 times)

WayBack

  • Guest
Some help with pragma data_seg()
« on: April 18, 2011, 04:49:38 PM »
Hi,

I'm trying to create a shared data section in a DLL. As best as I can find or remember, this should do that:
Code: [Select]
#pragma data_seg(".shared")
int nFout = 0;
int nFots = 0;
// ...
#pragma data_seg()
#pragma comment(linker, "/SECTION:.shared,RWS")
but instead it gives me a warning:
Quote
POLINK: warning: /SECTION:.shared ignored; section is missing.
And a quick check with podump.exe confirms the section isn't created.

Could someone tell me what is wrong?

I'm compiling a simple non-unicode x86 test dll with - Version 6.50.4 Release Candidate #3 (Win64)

Thanks

CommonTater

  • Guest
Re: Some help with pragma data_seg()
« Reply #1 on: April 18, 2011, 06:37:48 PM »
Have you tried it without the dot at the beginning... something like myshared instead of .shared?


Here's a working example...
Code: [Select]
#pragma data_seg("RMHook")
HINSTANCE   hdll    = NULL;               // dll handle
HWND        HWind   = NULL;               // handle of RMServer window
HHOOK       RMHook  = NULL;               // message hook handle
LAUNCHINFO  LInfo   = {0};                // info about program launch
#pragma data_seg()
#pragma comment(linker,"/SECTION:RMHook,S")
« Last Edit: April 18, 2011, 06:39:29 PM by CommonTater »

WayBack

  • Guest
Re: Some help with pragma data_seg()
« Reply #2 on: April 19, 2011, 12:45:26 AM »
Thanks, but this doesn't work for me either...
Code: [Select]
#pragma data_seg("RMHook")
HINSTANCE   hdll    = NULL;               // dll handle
HWND        HWind   = NULL;               // handle of RMServer window
HHOOK       RMHook  = NULL;               // message hook handle
//LAUNCHINFO  LInfo   = {0};                // info about program launch
#pragma data_seg()
#pragma comment(linker,"/SECTION:RMHook,S")
Quote
POLINK: warning: /SECTION:RMHook ignored; section is missing.

I'm placing the #pragma's below the includes and before DllMain in the main.cpp file that the Pelles C dll wizard spits out. All other settings are default and I haven't added any switches or libs or anything.

Is there something else I need to change before section will be created?

Attached below is the project that's not working.

CommonTater

  • Guest
Re: Some help with pragma data_seg()
« Reply #3 on: April 19, 2011, 02:15:30 AM »
Yes it failed... because none of the variables in the section are used in your trial run...

If I do this...
Code: [Select]
BOOL APIENTRY DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            hdll = hInstDLL;
            break;

Now, the section is created because hdll is a variable in that section.

Going back to your original example at the top of the thread ... first I would lose the . and just call it "shared" or "mydata" or such... second, if you assign a value (i.e. make a reference to) to either or both of your variables you should see that the section is created.  The problem is most likely part of the optimization scheme, unreferenced variables are not included in final programs and empty sections are not retained by the linker.






« Last Edit: April 19, 2011, 02:19:49 AM by CommonTater »

WayBack

  • Guest
Re: Some help with pragma data_seg()
« Reply #4 on: April 19, 2011, 07:14:07 AM »
Yes, that was the problem. Thanks, CommonTater.

And I can understand what you're saying about ".share". I can see where it might not be the best name to use. Changing that and actually using the shared variables in the code fixed it right up.

Thanks again.

CommonTater

  • Guest
Re: Some help with pragma data_seg()
« Reply #5 on: April 19, 2011, 02:28:32 PM »
No worries...