#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Malaysia
    Posts
    12
    Rep Power
    0

    Unhappy Borland C++ Builder 6 - SNMP


    HI there...I'm now doing a college project on a network management simulator program. The project scope is easy, but hard to implement. The task of the program is just to detect the devices in a LAN, and display them graphically in the program, with the relevant information for each device. The devices are displayed with links...so it would be like a network topology viewer.

    I think WinSNMP should be able to do the task, but the problem is I don't know how to use it. I just started to write a single line of codes, which is:

    void __fastcall Tmonitor::btn_OKClick(TObject *Sender)
    {
    unsigned long *nMajorVersion, *nMinorVersion, *nLevel;
    unsigned long *nTranslateMode, *nRetransmitMode;

    SnmpStartup(nMajorVersion, nMinorVersion, nLevel, nTranslateMode,
    nRetransmitMode);
    }

    I'm using Borland C++ Builder 6...and when i try to compile the program, I got this error msg:

    [Linker Error] Unresolved external 'SnmpStartup' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\CNDSPROJECT.OBJ

    I've include the winsnmp.h file, and the lib file with the code: USELIB ("C:\WINNT\system32\Wsnmp32.dll");

    Can anyone help me on this? I'm really new in network programming. Thanks....[SIZE=3]
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,642
    Rep Power
    4247
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,183
    Rep Power
    2222
    I'm not familiar with WinSNMP, but it looks like there should be a .LIB file that should have come with it and that you need to link in statically. The DLL, Wsnmp32.dll, gets accessed when you run, but it cannot be used to resolve any external references when you build your executable.

    Build instructions should have come with the product telling you what static libraries you would need to link in.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Malaysia
    Posts
    12
    Rep Power
    0
    So that means I need to include another library files? Does the static library that I should use dependent on what .dll I've used?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Malaysia
    Posts
    12
    Rep Power
    0
    Scorpions4ever: Thanks for the link =) I'll try to understand it...hehe!

    I hope to receive more info on WinSnmp from you guyz. Your help is very much appreciated ;)
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,183
    Rep Power
    2222
    First the disclaimers:
    Since 1995, I've worked mainly in embedded C programming.

    My 32-bit Windows programming has been primarily with Visual C++; until last week none of it involved working directly with a DLL.

    I've just been brought in on an existing Visual C++ project which uses two DLLs. What the previous programmer had done to call a function in the DLL was to explicitly load the DLL and set a function pointer to it using the GetProcAddress() function. As far as I know, this is the way that it needs to be done, at least in Visual C++ (I cannot speak for C++Builder).

    Now, knowing those things, you can evaluate what I say.

    I was thinking specifically of Winsock in my earlier response. In order to add sockets to a program (I assume that's embedded in WinSNMP), I need to use the wsock32.dll DLL file. However, I also do not need to set up any function pointers, but rather I call the functions "directly". You see, to call the connect() sockets function I just use it, but I actually call a function by that name in the wsock32.lib static library and it handles the necessary calls to the DLL. So here we have an example of needing to link in a static library in order to use a DLL.

    With that in mind, I thought that WinSNMP could be set up in a similar manner. This suspicion was supported by the name of the function you are having trouble with, SnmpStartup; in Winsock programming in order to load and initialize the wsock32 DLL you call WSAStartup. You can see the similarity, plus the WinSNMP programmers would be very familiar with Winsock programming and so could be likely to pattern their own approach after Winsock's approach.

    Furthermore, to my knowledge, the linker cannot resolve an address that is inside a DLL. To my knowledge, the external address must be either to another module or to a static library. To my knowledge, it's up to the program to handle late-binding (linking to a DLL at run-time -- please note that in Winsock it's wsock32.lib that handles this). To my knowledge, calling a function directly by name, as you are doing in your call to SnmpStartup, requires early-binding (linking at build-time, AKA "compile time"); if the linker cannot find an actual address to bind an external reference to, then the build will fail with an "undefined external reference" error.

    So that is why I asked whether WinSNMP includes a static library, possibly named Wsnmp32.lib . Or whether their instructions tell you that you will need to include a particular static library (RTFM).

    I just now did a search on my Win2000 machine which does not have WinSNMP on it. I found Wsnmp32.dll in my c:\winnt\system32 directory and I found the static library, Wsnmp32.lib, in my Visual C++ library directory. So the DLL comes with the operating system and the .LIB comes with the compiler. Therefore, WinSNMP does not need to include those two libraries in their distribution.

    So my suggestion is for you to search your C++Builder library directory for wsnmp32.lib or something similar. Then in your project's linker setup include that .LIB library file.

    And check the WinSNMP documentation again or their online FAQ, if they have one, to see what it says about what libraries you will need to link in.
    Last edited by dwise1_aol; September 27th, 2003 at 11:42 AM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Malaysia
    Posts
    12
    Rep Power
    0
    Well, in builder there's no wsnmp32.lib file. I copied the wsnmp32.lib from VC++ to builder's folder, but the same problem occured. So i went to the command prompt and use the code "implib wsnmp32.lib wsnmp32.dll" to make the static link (i think?), and then from the system32 folder i copied the created wsnmp32.lib file to my builder folder. Then in my form's code, I use the "USELIB()" func to call the LIB file (as same as what i typed in my 1st thread, just that this time it's LIB file)...the same prob occured too.

    Can you specifically tell me how to deal with those DLL n LIB? I'm really desperate with it :confused:
    Last edited by shellylai; September 28th, 2003 at 11:01 AM.
  14. #8
  15. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,183
    Rep Power
    2222
    OK, I Google'd on WinSNMP and Borland and found a page of samples for Borland products (actually I found the readme.txt file and backed up from there.

    Go to the page http://www.winsnmp.com/samples/delphi/ . Despite the name, it has files for C++Builder as well as for Delphi. One of them is winsnmp.lib . Another one is a makefile for their snmpdemo.cpp sample program; please notice that it does require winsnmp.lib:
    Code:
    # ---------------------------------------------------------------------------
    VERSION = BCB.01
    # ---------------------------------------------------------------------------
    !ifndef BCB
    BCB = $(MAKEDIR)\..
    !endif
    # ---------------------------------------------------------------------------
    PROJECT = SnmpDemo.exe
    OBJFILES = SnmpForm.obj WinSNMP.obj SnmpDemo.obj
    RESFILES = SnmpDemo.res
    RESDEPEN = $(RESFILES) SnmpForm.dfm
    LIBFILES = winsnmp.lib
    DEFFILE = 
    # ---------------------------------------------------------------------------
    CFLAG1 = -Od -Hc -w -k -r- -y -v -vi- -c -a4 -b- -w-par -w-inl -Vx -Ve -x
    CFLAG2 = -I$(BCB)\include;$(BCB)\include\vcl;. -H=$(BCB)\lib\vcld.csm 
    PFLAGS = -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE \
       -U$(BCB)\lib\obj;$(BCB)\lib -I$(BCB)\include;$(BCB)\include\vcl;. -v -$Y -$W \
       -$O- -JPHNV -M     
    RFLAGS = -i$(BCB)\include;$(BCB)\include\vcl;. 
    LFLAGS = -L$(BCB)\lib\obj;$(BCB)\lib -aa -Tpe -x -v -V4.0 
    IFLAGS = 
    LINKER = ilink32
    # ---------------------------------------------------------------------------
    ALLOBJ = c0w32.obj $(OBJFILES)
    ALLRES = $(RESFILES)
    ALLLIB = $(LIBFILES) vcl.lib import32.lib cp32mt.lib 
    # ---------------------------------------------------------------------------
    .autodepend
    
    $(PROJECT): $(OBJFILES) $(RESDEPEN) $(DEFFILE)
        $(BCB)\BIN\$(LINKER) @&&!
        $(LFLAGS) +
        $(ALLOBJ), +
        $(PROJECT),, +
        $(ALLLIB), +
        $(DEFFILE), +
        $(ALLRES) 
    !
    
    .pas.hpp:
        $(BCB)\BIN\dcc32 $(PFLAGS) { $** }
    
    .pas.obj:
        $(BCB)\BIN\dcc32 $(PFLAGS) { $** }
    
    .cpp.obj:
        $(BCB)\BIN\bcc32 $(CFLAG1) $(CFLAG2) -o$* $* 
    
    .c.obj:
        $(BCB)\BIN\bcc32 $(CFLAG1) $(CFLAG2) -o$* $**
    
    .rc.res:
        $(BCB)\BIN\brcc32 $(RFLAGS) $<
    #-----------------------------------------------------------------------------
    I am disappointed with them. I would have expected them to have provided the information necessary for using their product with the product.

    Hope this helps.

IMN logo majestic logo threadwatch logo seochat tools logo