Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Importing initializers in plugins on Win32

From: Ulf Lamping <ulf.lamping@xxxxxx>
Date: Wed, 28 Feb 2007 18:28:35 +0100
> -----Ursprüngliche Nachricht-----
> Von: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
> Gesendet: 28.02.07 16:34:26
> An: Wireshark Developer mailinglist <wireshark-dev@xxxxxxxxxxxxx>
> Betreff: [Wireshark-dev] Importing initializers in plugins on Win32


> Hi list,
> 
> I've been trying to import some of the true_false strings provided by
> libwireshark.dll into a plugin, but can't get the compiler to grock it.
> 
> Here's the relevant code snippet from my source file.
> 
> #include <epan/packet.h>
> #include <epan/xdlc.h>
> 
>   static hf_register_info hf[] =
>   {
> 	{ &hf_lap_p,
> 	    { "Poll", "lap.control.p", FT_BOOLEAN, 8,
> [line 683]    TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
>    ....
>   }
> 
> Compiling this file, using VC6, gives
> 
> packet-.c
> packet-.c(683) : error C2099: initializer is not a constant
> packet-.c(683) : warning C4047: 'initializing' : 'const void *' differs in levels of indirection from 'const int '
> packet-.c(683) : warning C4047: 'initializing' : 'unsigned int ' differs in levels of indirection from 'char [1]'
> packet-.c(683) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'void *'
> 
> So I looked at the export of the symbol flags_set_truth. As documented
> these shall be marked WS_VAR_IMPORT, which they are (see epan/tfs.h).
> They are also set in libwireshark.def as DATA.
> The nmake file is of the latest fashion with
> CFLAGS=/DHAVE_WIN32_LIBWIRESHARK_LIB /D_NEED_VAR_IMPORT_ $(CFLAGS) so the
> VAR_IMPORT should be covered.
> 
> I've got the sneaking suspicion that you can't import constants this way
> from another DLL, although exporting dscp_vals[] from
> epan/dissectors/packet-ip.c does work!?
> 
> Anyone a suggestion how to properly address this?
> 

I've recently stumbled across this problem myself, when moving the CBA dissector into the PROFINET plugin.

AFAIK, this is caused as the compiler cannot know the size of this. So you *can* use this value inside the plugin (e.g. using val_to_str), but you cannot use it to *initialize* the hf_register_info.

Regards, ULFL
_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066