Wireshark-dev: Re: [Wireshark-dev] Troubles with ASN generated code
From: Graham Bloice <graham.bloice@xxxxxxxxxxxxx>
Date: Sun, 21 May 2017 22:54:50 +0100


On 21 May 2017 at 20:57, Guy Harris <guy@xxxxxxxxxxxx> wrote:
On May 21, 2017, at 12:43 PM, Graham Bloice <graham.bloice@xxxxxxxxxxxxx> wrote:

> I haven't looked at the specific issue, but Windows can export data from a DLL into another DLL.

Yes, but if DLL A exports a data item called "fff" that's imported by DLL B, and DLL B uses it in this fashion:

        static struct xyzzy foo {
                ...

                &fff,

                ...

        };

will that work?  You might be able to do

        xxx = fff;

but can you take the address of the exported item and use that to initialize a pointer in a static data structure.
 
It would appear not in a static initializer list. I can do it piecemeal, e.g. foo.member = &fff.  BTW, I'm testing with VS2015.

If I try to assign &fff in an initialiser list I get an "error C2099: initializer is not a constant".
 

And will it work if DLL B is loaded at run time?

The piecemeal assignment does.  I've attached dlltest2.zip to show this.  main.c is now compiled with no reference to dllimport.lib, i.e.

cl main.c dllexport.lib

 

That's the specific issue here.

> The data to be exported should be declared __declspec(dllexport),

That's WS_DLL_PUBLIC_DEF from ws_symbol_export.h, if we're building for Windows with MSVC and WS_BUILD_DLL is defined.

> and when it is required to be imported declared as __declspec(dllimport).

That's WS_DLL_PUBLIC_DEF from ws_symbol_export.h, if  we're building for Windows with MSVC and WS_BUILD_DLL *isn't* defined.

WS_DLL_PUBLIC is "WS_DLL_PUBLIC_DEF extern".

So you *declare* data items, in header files, with WS_DLL_PUBLIC, and you *define* them, in source files, with WS_DLL_PUBLIC_DEF.


--
Graham Bloice

Attachment: dlltest2.zip
Description: Zip archive