Create a .DLL used by VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DreamU
    New Member
    • Jul 2008
    • 6

    Create a .DLL used by VB

    I created a .dll using Visual C++ Express 8.0. For testing purposes, it couldn't be simpler:

    extern "C" __declspec(dlle xport) void __stdcall NVPM_Init();
    __declspec(dlle xport) void __stdcall NVPM_Init() {
    return;
    }

    In the VB program if I try to add the reference to this .dll it says "file could not be added. Please make sure the file is accessible and that it is a valid assembly or COM component".

    The VB program uses a third party .DLL I downloaded, the popular Zedgraph, which works fine. When I use CFF Explorer to view ZedGraph is says "Portable Executable 32 .NET Assembly". When I look at my custom .dll it says only "Portable Executable 32", in other words, missing the ".NET Assembly" suffix. I assume this is the source of my problem.

    How do I tell Visual C++ to make my .DLL a '.NET Assembly'? I have tried it as both a Win32 Console App and a Win32 Project but doesn't seem to matter. The /NOASSEMBLY switch does not exist in the command line.
  • DreamU
    New Member
    • Jul 2008
    • 6

    #2
    Update:

    I found that if I change the linker options in C++ to add CLR support (/CLR) then I am able to 'Add Reference' to the .DLL in Visual Basic. And, in fact, using CFF Explorer now shows this .DLL to be a 'Portable Executable 32 .NET Assembly'. Great that was a little progress.

    But in Visual Basic in the Import Statement it kept complaining (pop-up) that there were no public members. So, I changed the C++ code to be a class, instead of the simple code shown earlier. Curiously, when I did this Visual C++ popped up a message saying it was going to have to add CLR support. That jives with what I just did earlier so Great, a little more progress.

    Finally, I am still stumped in Visual Basic. The program runs up until the first call into the .DLL member at which point I get an error saying
    'Unable to find an entry point named 'NVPM_Init' in DLL 'NVPerfSDK'.
    I don't understand because if I use Object Browser in VB it shows that member (NVPM_Init) in the .DLL. So, why isn't it found now at runtime - the designer found it OK.

    Maybe at this point I need to take this question over to the VB forum. Not sure.

    I created DLL's in C++ 10 years ago and ran them under VB. I don't remember having to do any of this stuff. In fact, my code back then looked like all the examples of DLL you find in google - simple stuff. Will this thing only work as a class definition?

    Comment

    • DreamU
      New Member
      • Jul 2008
      • 6

      #3
      Update 2:

      Ok, got it to work. Because the VB Object Browser saw the C++ Class member in the .DLL I did not think I needed the

      __declspec(dlle xport)

      in front of the class member name. Well, you do, and when I added it back (it was always in the non-class .dll code) the VB code worked fine and accessed the .DLL.

      So, I am still curious: is all this necessary? What about all those simple .DLL examples on the web that create a .DLL without using a class structure? (Has the world changed that much since I did this 10 years ago?)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Yep.

        The good old days creating a dll and using something like GetProcAddress are goiine forever. Now yout can import the dll, call members by implementing IDispatch, use Invoke, use the CLR, etc.., etc..

        Comment

        Working...