Like Tree1Likes

Visual Studio DLL and Visual Basic

This is a discussion on Visual Studio DLL and Visual Basic within the C Programming forums, part of the General Programming Boards category; Okay. I've been struggling with this for a long time. I've decided to finally ask it out here and see ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    28

    Visual Studio DLL and Visual Basic

    Okay. I've been struggling with this for a long time. I've decided to finally ask it out here and see if I can make it work. I have code that I can successfully build on a couple of different compilers (Borland and Pelles) as a DLL and use it from a program written in Visual Basic. We are using the __stdcall for the DLL. I can also compile and produce a DLL using Visual Studio. However, the DLL produced by Visual Studio cannot be called from Visual Basic. We call it but nothing happens. We do not know why. The exports all look good, etc. None of the code is different. So, I have to assume that it is a setting or something. But, we cannot find it. Ideas? Is there an issue with Visual Studio produced DLLs and Visual Basic? Are there workarounds?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,701
    >> We call it but nothing happens.
    Show the declaration for "it" (the function) in both VB and C source.

    gg

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    Declaration of DLL from C code.

    int __stdcall DLLNAME(struct bufferone far *a_one,
    struct buffertwo far *b_one,
    struct buffertwo far *b_two,
    struct buffertwo far *b_three)

    Call from Visual Basic Code

    Declare Function DLLNAME Lib "dllname.dll" _
    (ByRef a_one As bufferone, _
    ByRef b_one As buffertwo, _
    ByRef b_two As buffertwo, _
    ByRef b_three As buffertwo) As Integer

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,701
    Look at the DLL built by VS using Dependency Walker: Dependency Walker (depends.exe) Home Page
    Do you see the expected exports?
    Do they look similar to the exports produced by Borland/Pelles?

    gg

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    It looks like the VS version is not exporting the function. The outputs from Dependency Walker are virtually identical except the VS version has MSVCR80D.DLL in the output. Also in the output pane, E, the function is not listed. In the Pelles it is listed. So, there's the trouble. What's the cure? Why isn't it being exported? Something really stupid is slipping past me here.

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    Since this looks like VB 6, the declarations you posted are incompatible. A VB Integer (16-bits) is not the same size as a C int (32-bits). You might want to post the makeup of your two structs, if they are similarly mismatched loading the DLL will be the least of your problems.

    If this is VB.net, then ignore the above.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,768

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,701
    >> the VS version has MSVCR80D.DLL
    Then you were looking at a debug build of your DLL. To use your VS DLL on other PC's, you'll need to use a release build and make sure the PC has had the VC++ Redistributable Package installed (or link with the CRT statically).

    >> Also in the output pane, E, the function is not listed.
    If you are using a .DEF file for DLL exports, make sure it's part of the VS solution/project. Using "__declspec(dllexport)" in source is an alternative to using a .DEF file.

    gg

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    Okay, with your help (thank you, thank you), I've got a successful build that we're able to call from Visual Basic in Windows 7. We're building the DLL in Visual Studio 5 SP3 on a Windows 7 machine. We can call the DLL on a Windows 7 machine. However, when we try to call the same DLL from XP and Server 2003 machines it fails. So, we've got some type of incompatibility between included components or there are options that should be set to make this DLL callable across all platforms. What should I be looking for?

    Thank you for all of the valuable assistance so far. I do appreciate it.

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    If you're on Windows 7 ... are you building a 64bit dll?
    That's not going to work on any 32 bit operating system.

    The rules for this are simple...
    You cannot load a 64 bit DLL in a 32 bit OS.

    On a 64 bit OS...
    You cannot load a 64 bit DLL in a 32 bit process.
    You cannot load a 32 bit DLL in a 64 bit process.

    This leaves the rather unenviable task of having to compile everything twice with different file names.
    (Typically ... dllname.dll and dllname64.dll )

  11. #11
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    Building on a 64-bit system but for Win32.

  12. #12
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    In depends.exe, we still have MSVCR80.DLL even though we have debugging off for a release build. Why is that still included? How do I remove that? Could that be our issue?

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mathguy View Post
    Building on a 64-bit system but for Win32.
    Understood... but this is an error I've made before... double check that you are actually building a 32 bit DLL.

  14. #14
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    Okay will check to be sure. How should I be totally sure?

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mathguy View Post
    Okay will check to be sure. How should I be totally sure?
    You're going to have to trust the compiler and linker settings...

    You will be totally sure when it works.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ and Visual Studio 2010
    By 03jh01 in forum C++ Programming
    Replies: 5
    Last Post: 10-03-2010, 05:03 AM
  2. visual studio 6 and visual studio.net difference
    By gemini_shooter in forum Tech Board
    Replies: 5
    Last Post: 02-04-2006, 01:32 AM
  3. Replies: 1
    Last Post: 05-26-2004, 10:59 AM
  4. Replies: 1
    Last Post: 04-20-2002, 07:49 AM
  5. Moving from Visual Basic to Visual C++
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2002, 10:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21