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

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

From: Jaap Keuter <jaap.keuter@xxxxxxxxx>
Date: Wed, 28 Feb 2007 16:22:27 +0100 (CET)
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?

Thanx,
Jaap